Type.GetInterface() 方法在 C# 中
C# 中的 Type.GetInterface() 方法用于获取当前类型实施或继承的特定接口。
语法
以下是语法 −
public Type GetInterface (string name); public abstract Type GetInterface (string name, bool ignoreCase);
示例
我们现在来看一个示例以实现 Type.GetInterface() 方法 −
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
示例
我们现在来看另一个示例来实现 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);
}
}输出
将生成以下输出 −
Interface = System.IFormattable
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP