我有时用
if (this._currentToolForeColor.HasValue)
return this._currentToolForeColor.Value;
else
throw new InvalidOperationException();
其他时候我用
if (this._currentToolForeColor.HasValue)
return this._currentToolForeColor.Value;
throw new InvalidOperationException();
我知道这两者是等价的,但我不确定哪个是最好的以及为什么。
这更进一步,因为您可以使用其他执行控制语句,例如刹车或继续:
while(something)
{
if(condition)
{
DoThis();
continue;
}
else
break;
}
相对
while(something)
{
if(condition)
{
DoThis();
continue;
}
break;
}
编辑1:是的,循环示例很糟糕,因为它们是合成的(即:弥补这个问题),不像第一个是实用的。