编码:

class Program
    {
        static void Main(string[] args)
        {
            int obj1 = 2;
            Test<int> test1 = new Test<int>(obj1);
            Console.WriteLine("int:" + test1.obj);
            string obj2 = "hello world";
            Test<string> test2 = new Test<string>(obj2);
            Console.WriteLine("String:" + test2.obj);
            Console.Read();
        }
    }
 
    class Test<T>
    {
        public T obj;
        public Test(T obj)
        {
            this.obj = obj;
        }
}
View Code

相关文章: