The C# LastIndexOfAny method is used to find index position of the last occurrence of one or more characters specified in this string.
Signature
Example
public int LastIndexOfAny(Char[] ch)
public int LastIndexOfAny(Char[], Int32)
public int LastIndexOfAny(Char[], Int32, Int32)
Parameter
ch: it is a character type array.
Return
It returns integer value.
C# String LastIndexOfAny Method Example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "abracadabra";
char[] ch = {'r','b'};
int index = s1.LastIndexOfAny(ch);//Finds 'r' at the last
Console.WriteLine(index);
}
}
Output:
C# String LastIndexOfAny Method Example 2
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "abracadabra";
char[] ch = {'t','b'};
int index = s1.LastIndexOfAny(ch);//Finds 'b' at the last
Console.WriteLine(index);
}
}
Output: