The IndexOf() method returns the index number of the first matched character whereas the LastIndexOf() method returns the index number of the last matched character.
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";
int first = s1.IndexOf('l');
int last = s1.LastIndexOf('l');
Console.WriteLine(first);
Console.WriteLine(last);
}
}
Output: 2 3
