泛型

来源:互联网 发布:潘家园配眼镜 知乎 编辑:程序博客网 时间:2024/06/06 20:31
class Program
    {
        static void Main(string[] args)
        {
            B<int> s = new B<int>();
            s.print(123);
            s.prin(21);
            Console.ReadKey();
        }
    }
    abstract class A<T>  //没有固定是什么类型所有更加灵活
    {
        public void prin(T t) {
            Console.WriteLine(t);
        }
    }
    class B<T> : A<T>
    {
        public void print(T t)
        {
            Console.WriteLine(t);
        }
    }
0 0