C#泛型接口

使用泛型可以定义接口,在接口中定义的方法可以带泛型参数。----------《C#高级编程(第7版)》清华大学出版社

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            TestClass testClass = new TestClass();
            testClass.CWType(123);
            TestClass2 testClass2 = new TestClass2();
            testClass2.CWType("123");
            Console.ReadKey();
        }
    }

    public interface ITestInter<in T>
    {
        void CWType(T t);
    }
    public class TestClass : ITestInter<int>
    {
        public void CWType(int num)
        {
            Console.WriteLine(num.GetType());
        }
    }

    public class TestClass2 : ITestInter<String>
    {
        public void CWType(String str)
        {
            Console.WriteLine(str.GetType());
        }
    }

}
原文地址:https://www.cnblogs.com/xiaobao2017/p/12186331.html