.Net泛型简介

protected void Page_Load(object sender, EventArgs e)
    {
        Cat cat = new Cat();
        cat.Name = "Lily";
        Pet<Cat> pet = new Pet<Cat>();
        pet.T1 = cat;
        Response.Write(pet.T1.Name);//输出了Lily
    }


    public class Cat
    {
        public string Name;
    }

    public class Pet<T>
    {
        private T _t;
        public T T1
        {
            get
            {
                return _t;
            }
            set
            {
                _t = value;
            }
         
        }

    }

猜你喜欢

转载自blog.csdn.net/hhw199112/article/details/79156652