String Lastindexofany() - C# Tutorial
C# Course / Strings / String Lastindexofany()

String Lastindexofany()

BLUF: Mastering String Lastindexofany() is essential for building robust applications with the .NET ecosystem. This tutorial provides clear explanations and practical examples to help you understand and apply this C# concept.
Enterprise Development Tip: String Lastindexofany()

C# is a powerful, modern language for enterprise solutions. Discover how String Lastindexofany() enhances your development workflow in the guide below.

The C# LastIndexOfAny function is employed to determine the index position of the final instance of one or multiple characters defined within the 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:

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience