获取 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