वर्तमान प्रकार द्वारा कार्यान्वित या इनहेरिट किए गए सभी इंटरफेस को प्राप्त करने के लिए, कोड इस प्रकार है -
उदाहरण
using System;
public class Demo {
public static void Main() {
Type type = typeof(float);
Type myInterface = type.GetInterface("IFormattable",true);
Type[] myInterfaces = type.GetInterfaces();
Console.WriteLine("Interface = "+myInterface);
Console.WriteLine("All the Interfaces...");
for (int i = 0; i < myInterfaces.Length; i++)
Console.WriteLine(""+myInterfaces[i]);
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
Interface = System.IFormattable All the Interfaces... System.IComparable System.IFormattable System.IConvertible System.IComparable`1[System.Single] System.IEquatable`1[System.Single]
आइए एक और उदाहरण देखें -
उदाहरण
using System;
public class Demo {
public static void Main() {
Type type = typeof(int);
Type myInterface = type.GetInterface("IFormattable");
Type[] myInterfaces = type.GetInterfaces();
Console.WriteLine("Interface = "+myInterface);
Console.WriteLine("All the Interfaces...");
for (int i = 0; i < myInterfaces.Length; i++)
Console.WriteLine(""+myInterfaces[i]);
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
Interface = System.IFormattable All the Interfaces... System.IComparable System.IFormattable System.IConvertible System.IComparable`1[System.Int32] System.IEquatable`1[System.Int32]