C# Type GetInterface(String)

Description

Type GetInterface(String) searches for the interface with the specified name.

Syntax

Type.GetInterface(String) has the following syntax.


public Type GetInterface(
  string name
)

Parameters

Type.GetInterface(String) has the following parameters.

  • name - The string containing the name of the interface to get. For generic interfaces, this is the mangled name.

Returns

Type.GetInterface(String) method returns An object representing the interface with the specified name, implemented or inherited by the current Type, if found; otherwise, null.

Example

The following code example uses the GetInterface(String) method to search the Hashtable class for the IDeserializationCallback interface, and lists the methods of the interface.


using System;/* w w  w . j ava 2 s  .  c  om*/
using System.Reflection;
using System.Collections;
public class MainClas
{
    public static void Main()
    {
        Hashtable hashtableObj = new Hashtable();
        Type objType = hashtableObj.GetType();
        MethodInfo[] arrayMethodInfo;

        arrayMethodInfo = objType.GetInterface("IDeserializationCallback").GetMethods();
        Console.WriteLine("\nMethods of 'IDeserializationCallback' Interface :");
        for (int index = 0; index < arrayMethodInfo.Length; index++)
        {
            Console.WriteLine(arrayMethodInfo[index].ToString());
        }
    }


}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version