这段代码是什么意思?

0 c# conditional visual-studio

if (exist.IndexOf("true") == -1)
{
    //first condition

}
else
{
    // second condition
}
Run Code Online (Sandbox Code Playgroud)

如果我使用它的意义是什么(exist.IndexOf("true") != -1)

dev*_*ity 13

好吧,IndexOf如果找不到该项,通常会返回-1.因此,如果字符串"true"不存在,则将执行第一个条件exist.


Hun*_*hpu 5

您可以在MSDN中看到" String.IndexOf Method(String) ".


lep*_*pie 5

或者,

if (!exist.Contains("true"))
{
  //first condition
}
else
{
  // second condition
}
Run Code Online (Sandbox Code Playgroud)