泛型

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);
        }
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章