현재 Type에 의해 구현되거나 상속된 모든 인터페이스를 가져오려면 코드는 다음과 같습니다. -
예시
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]