【发布时间】:2010-12-05 07:06:50
【问题描述】:
我一直想知道为什么在下面的例子中可以不初始化实例字段(依赖于它将有它的默认值)并访问它,而局部变量显然是必须初始化,即使我将它初始化为默认值,它还是会得到......
public class TestClass
{
private bool a;
public void Do()
{
bool b; // That would solve the problem: = false;
Console.WriteLine(a);
Console.WriteLine(b); //Use of unassigned local variable 'b'
}
}
【问题讨论】: