首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > C# > C# 创建一个泛型接口

C# 创建一个泛型接口

  • 资源大小:20.08 kB
  • 上传时间:2021-06-29
  • 下载次数:0次
  • 浏览次数:0次
  • 资源积分:1积分
  • 标      签: C#源码

资 源 简 介

C# 创建一个泛型接口的例子,创建一个泛型接口的代码和方法如下:   public interface IGenericInterface   {    T CreateInstance(); //接口中调用CreateInstance方法   }   //实现上面泛型接口的泛型类   //派生约束where T : TI(T要继承自TI)   //构造函数约束where T : new()(T可以实例化)   public class Factory : IGenericInterface where T : TI, new()   {    public TI CreateInstance()//创建一个公共方法CreateInstance    {    return new T();    }   }   class Program   {    static void Main(string[] args)    {    //实例化接口    IGenericInterface factory =   Factory();    //输出指定泛型的类型    Console.WriteLine(factory.CreateInstance().GetType().ToString());    Console.ReadLine();    }   }

文 件 列 表

codesc.net
FXInterface
FXInterface
FXInterface
bin
Debug
FXInterface.exe
codesc.net
VIP VIP
0.172441s