【发布时间】:2017-12-21 09:49:21
【问题描述】:
static void Main(string[] args)
{
int i = 10;
Program th = new Program();
Thread t2 = new Thread(() => thread2(out i));
t2.Start();
Thread t1 = new Thread(() => thread1(i));
t1.Start();
Thread.Sleep(5000);
Console.WriteLine("Main thread exits." + i);
Console.ReadLine();
}
static void thread1(int i)
{
Console.WriteLine(i);
i = 100;
}
static void thread2(out int i) // what should be the value of i???
{
Thread.Sleep(5000);
i = 21;
Console.WriteLine(i);
}
当我们传递参数时,在被调用方法中接收到的值应该是什么? “无论是零还是我们传递的值”
【问题讨论】:
-
你试过运行这段代码吗?发生了什么?
-
你问
out参数是什么? -
勾选的答案here会有所帮助
-
我不明白你的问题。在离开方法之前,您必须给每个输出参数一个值。或者你是在问哪个
i会被thread2修改?试试看,你会看到。 -
谢谢大家,我的问题得到了答案
标签: c# .net parameters out