类的泛型快速举例(苹果装箱)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ch10CardLib;
namespace Service4
{
    class Apple
    {
        public string Name;

    }

    class Box<TCargo>
    {
         
        public TCargo Cargo;

    }


    class Program
    {

       
        static void Main(string[] args)
        {
            Apple myApple = new Apple() { Name = "GoodApple"};

            Box < Apple> box1 = new Box<Apple>() {Cargo = myApple };

            Console.WriteLine(box1.Cargo.Name);
            Console.ReadKey();

        }





    }
}

发布了271 篇原创文章 · 获赞 44 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq_38992403/article/details/105432733