Phương thức Type.GetInterface () trong C # được sử dụng để có được một giao diện cụ thể được Kiểu hiện tại triển khai hoặc kế thừa.
Cú pháp
Sau đây là cú pháp -
public Type GetInterface (string name); public abstract Type GetInterface (string name, bool ignoreCase);
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ để triển khai phương thức Type.GetInterface () -
using System;
public class Demo {
public static void Main(){
Type type = typeof(double);
Type myInterface = type.GetInterface("IFormattable");
Console.WriteLine("Interface = "+myInterface);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Interface = System.IFormattable
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ khác để triển khai phương thức Type.GetInterface () -
using System;
public class Demo {
public static void Main(){
Type type = typeof(float);
Type myInterface = type.GetInterface("IFormattable",true);
Console.WriteLine("Interface = "+myInterface);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
Interface = System.IFormattable