views:

239

answers:

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

        }
        else
        {
           // second condition
        }

what is means of it if i use (exist.IndexOf("true") != -1)

+13  A: 

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.

developmentalinsanity
+2  A: 

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.

S.Mark
+3  A: 

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.

Blindy
+3  A: 

You can see in msdn

Hun1Ahpu
first accepted RTFM answer iv seen :o
Blindy
+1  A: 

Looks like exist holds a string. Being that correct, IndexOf returns the index of the first occurrence of a substring (in this case, true). If -1 is returned, then the substring wasn't found.

jweyrich
+5  A: 

Alternatively,

if (!exist.Contains("true"))
{
  //first condition
}
else
{
  // second condition
}
leppie
A: 

//if (exist.IndexOf("true") == -1)//bad programing tecnic same as //if(exist.IndexOf("True") { //first condition

    }
    else
    {
       // second condition
    }
Ayyappan.Anbalagan