C#線程傳遞對象參數

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

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            Student item = new Student
            {
                id = 1,
                name = "張三"
            };
            //線程傳遞對象
            Thread t = new Thread(() => ThreadStudent(item));
            t.Start();
        }
        private static void ThreadStudent(Student item)
        {
            Console.WriteLine(item.id.ToString());
            Console.WriteLine(item.name);
            Console.ReadLine();
        }
    }
    class Student
    {
        public int id{get;set;}
        public string name{get;set;}
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章