RCI*_*CIX 0 .net c# goto code-structure
我有一些结构如下的结构:
if (someStatement)
{
//...
if (SomeOtherStatement)
{
//..., possibly more cases like this
}
else
{
//goto warning;
//would otherwise repeat
//the MessageBox.Show here
}
}
else
{
//goto warning;
}
//...
warning:
MessageBox.Show("some warning");
Run Code Online (Sandbox Code Playgroud)
因为我厌恶复制代码,这是goto的少数有用的应用程序之一还是有更好的结构我可以使用?
那这个呢?
if (someStatement)
{
//...
if (SomeOtherStatement)
{
//..., possibly more cases like this
return; // in the inner-most case
}
}
MessageBox.Show("some warning");
Run Code Online (Sandbox Code Playgroud)