Find last index of a character in a string | C # program to find last index of character x in given string . ; Returns last index of x if it is present Else returns - 1. ; Driver code ; String in which char is to be found ; char whose index is to be found
using System ; class GFG { static int findLastIndex ( string str , char x ) { int index = - 1 ; for ( int i = 0 ; i < str . Length ; i ++ ) if ( str [ i ] == x ) index = i ; return index ; } public static void Main ( ) { string str = " geeksforgeeks " ; char x = ' e ' ; int index = findLastIndex ( str , x ) ; if ( index == - 1 ) Console . WriteLine ( " Character ▁ not ▁ found " ) ; else Console . WriteLine ( " Last ▁ index ▁ is ▁ " + index ) ; } }