ในการรับส่วนต่อประสานเฉพาะที่นำไปใช้หรือสืบทอดโดยประเภทปัจจุบัน รหัสจะเป็นดังนี้ -
ตัวอย่าง
using System;
public class Demo {
public static void Main() {
Type type = typeof(double);
Type myInterface = type.GetInterface("IFormattable");
Console.WriteLine("Interface = "+myInterface);
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Interface = System.IFormattable
ตัวอย่าง
เรามาดูตัวอย่างกัน −
using System;
public class Demo {
public static void Main() {
Type type = typeof(float);
Type myInterface = type.GetInterface("IFormattable",true);
Console.WriteLine("Interface = "+myInterface);
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Interface = System.IFormattable