泛型练习1

来源:互联网 发布:阿里云好还是腾讯云好 编辑:程序博客网 时间:2024/04/29 10:32

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace 练习
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread t = new Thread(N);
            t.Start();
            
        }
        public static void N()
        {
            List<Student> list = new List<Student>();

            list.Add(new Student("老孙"));
            list.Add(new Student("老zhu"));
            for (int i = 0; i < list.Count; i++)
            {
                list[i].name = "李四";
                //Console.WriteLine(list[i].name);
            }
            foreach (var item in list)//list 在这里是一种类型,所以要用item.name
            {
                Console.WriteLine(item.name);
            }
        }
    }
    public class Student
    {
        public string name;
        public Student(string name)
        {
            this.name = name;
        }
    }
}
0 0
原创粉丝点击