This program is given in the following website. If we use Step Into (F11 key) we can see value of "i" is changed into 3 then it is increased into 4. Again in the
while brackets 4 is add to 3 and "i" takes new 7. There no add sign in the brackets then how can 4 add to 3 and takes the value 7.
http://www.dotnetperls.com/indexofusing System;
class Program
{
static void Main()
{
// A.
// The input string.
string s = "I have a cat";
// B.
// Loop through all instances of the letter a.
int i = 0;
while ((i = s.IndexOf('a', i)) != -1)
{
// C.
// Print out the substring.
Console.WriteLine(s.Substring(i));
// D.
// Increment the index.
i++;
}
Console.ReadLine();
}
}
/*
ave a cat
a cat
at
*/