Type.GetInterfaces Method

July 28, 2014

When overridden in a derived class, gets all the interfaces implemented or inherited by the current Type.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public abstract Type[] GetInterfaces()

Return Value

Type: System.Type []
An array of Type objects representing all the interfaces implemented or inherited by the current Type.
-or-
An empty array of type Type, if no interfaces are implemented or inherited by the current Type.

ExceptionCondition
TargetInvocationException

A static initializer is invoked and throws an exception.

The GetInterfaces method does not return interfaces in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which interfaces are returned, because that order varies.

If the current Type represents a constructed generic type, this method returns the Type objects with the type parameters replaced by the appropriate type arguments.

If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the interface constraints and any interfaces inherited from class or interface constraints.

The following example gets the type of the specified class and displays all the interfaces that the type implements or inherits.



using System;
using System.Collections.Generic;

public class Example
{
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        outputBlock.Text += 
            "Interfaces implemented by Dictionary<int, string>:\n";
        foreach (Type ti in typeof(Dictionary<int, string>).GetInterfaces())
        {
            outputBlock.Text += ti.ToString() + "\n";
        }
    }
}

/* This example produces output similar to the following:

Interfaces implemented by Dictionary<int, string>:
System.Collections.Generic.IDictionary`2[System.Int32,System.String]
System.Collections.Generic.ICollection`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collections.Generic.IEnumerable`1[System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]]
System.Collection.IEnumerable
System.Collection.IDictionary
System.Collection.ICollection
 */


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft