獲取 C# 中當前 Type 實現或繼承的特定介面
若要取得當前 Type 實作或繼承的特定介面,請採用以下程式碼 −
範例
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP