
LastIndexOfAny searches for multiple characters in reverse. It returns the final position of any of a set of characters. This method provides this string functionality in the C# language.
This C# article looks at the LastIndexOfAny string method. It searches strings from their ends.

When you call LastIndexOfAny, you must provide a character array. One way of doing this is shown in the example. The example searches for the first instance of a 'd' or 'b' character starting from the end of the string. The position returned is 5, which is the final 'd' in the input string. The search terminates when something is found.
Program that uses LastIndexOfAny method [C#]
using System;
class Program
{
static void Main()
{
// Input string.
const string value = "ccbbddee";
// Search for last of any of these characters.
int index = value.LastIndexOfAny(new char[] { 'd', 'b' });
Console.WriteLine(index);
}
}
Output
5
The performance of LastIndexOfAny is not ideal. If you want to improve it, one thing you can do is store the character array argument in a field—static or instance—and then use a reference to that field as the argument. This will avoid an object creation on every call.
LastIndexOfAny is opposite the IndexOfAny method in the starting place of the search. For some string operations, these methods are very useful. We explained LastIndexOfAny and also pointed out one possible optimization you can use when invoking it.
IndexOfAny String Type