我有这个代码:
string[] args = Environment.GetCommandLineArgs();
bool grabNext;
foreach (string arg in args)
{
if (arg == "-AA")
{
grabNext = true;
}
if (grabNext)
{
incomingPlatypusID = arg;
}
}
...并且 Resharper 建议在内部范围内声明“bool grabNext”,所以当我允许时,代码变为:
string[] args = Environment.GetCommandLineArgs();
foreach (string arg in args)
{
if (arg == "-AA") ;
bool grabNext;
{
grabNext = true;
}
if (grabNext)
{
incomingPlatypusID = arg;
}
}
...然后,当然,我得到了一个错误消息,即“空控制语句体”
更新
实际上,我认为我需要的是以下内容,因为“-AA”是我获取下一个参数的指示:
foreach (string arg in args)
{
if (arg == "-AA")
{
grabNext = true;
continue;
}
if (grabNext)
{
PlatypusID = arg;
break;
}
}
更新 2
使用此代码,Resharper 不会抱怨:
private void AutoProvMainForm_Load(object sender, EventArgs e)
{
string[] args = Environment.GetCommandLineArgs();
bool grabNext = false;
foreach (string arg in args)
{
if (arg == "-AA")
{
grabNext = true;
continue;
}
if (grabNext)
{
PlatypusID = arg;
break;
}
}
}