为什么在以下情况下,MS C#编译器会抱怨“并非所有代码路径都返回一个值”?
public int Foo(bool flag)
{
if(flag)
{
return 1;
}
else
{
ThrowException(); // this method always throws an exception
// return -1; // why do I need to add this code that will never be called?
}
}
谢谢!