if (exist.IndexOf("true") == -1)
{
//first condition
}
else
{
// second condition
}
what is means of it if i use (exist.IndexOf("true") != -1)
if (exist.IndexOf("true") == -1)
{
//first condition
}
else
{
// second condition
}
what is means of it if i use (exist.IndexOf("true") != -1)
Well, typically IndexOf
returns -1 if the item couldn't be found. So, first condition will execute if the string "true" isn't present in exist
.
do first condition, when the text "true" is not found in string exist
, or do second condition if found. .IndexOf
return the position of string if found, and return -1 if not found.
The code tests if the string held in the variable exist
contains the substring "true", and if it does, it executes the "2nd condition" block, otherwise it executes the "1st condition" block.
Alternatively,
if (!exist.Contains("true"))
{
//first condition
}
else
{
// second condition
}
//if (exist.IndexOf("true") == -1)//bad programing tecnic same as //if(exist.IndexOf("True") { //first condition
}
else
{
// second condition
}