C#의 Type.GetInterfaces() 메서드는 현재 Type에 의해 구현되거나 상속된 모든 인터페이스를 가져오는 데 사용됩니다.
구문
다음은 구문입니다 -
public abstract Type[] GetInterfaces ();
예시
이제 Type.GetInterfaces() 메서드를 구현하는 예를 살펴보겠습니다. -
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]
예시
이제 Type.GetInterfaces() 메서드를 구현하는 또 다른 예를 살펴보겠습니다. -
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]