Program that uses IndexOf [C#]
static void Main()
// The input string.
const string s = "I am lucky.";
// Test with IndexOf.
if (s.IndexOf("lucky") != -1)
Console.Write("string contains 'lucky'");
Output string contains ‘lucky’ Description.In part A, it has an input string. This string is what we want to test. In part B, it calls IndexOf. IndexOf returns the location of the string ‘lucky’. It is not equal to -1, so the line is written to the console window.