static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
aa a = new aa();
a.age = i;
Thread thread = new Thread(new ThreadStart(a.getNum)); //参数和方法写到一个类里面也可以传参
thread.Start();
Thread.Sleep(2000);
}
}
public static void getNum(object i)
{
Console.WriteLine(((aa)i).age.ToString());
Console.ReadKey();
}
public class aa {
public string name { get; set; }
public int age { get; set; }
public void getNum()
{
Console.WriteLine(age.ToString());
Console.ReadKey();
}
}
2.带参数的
static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
aa a = new aa();
a.age = i;
Thread thread = new Thread(new ParameterizedThreadStart(getNum)); //这么写可以在getNum里设断点
thread.Start(a);//参数
Thread.Sleep(2000);
}
}