Returns the index of the last occurrence of a specified character within the current instance.
- value
- A Unicode character to locate.
- startIndex
- A int containing the index in the current instance from which to begin searching.
A int containing the index of the last occurrence of value in the current instance, if found; otherwise, -1.
Type Reason ArgumentNullException value is a null reference. ArgumentOutOfRangeException startIndex is less than zero or greater than the length of the current instance.
This method searches for the last occurrence of the specified character between the start of the string and the indicated index.
This method is case-sensitive.
The following example demonstrates the string.LastIndexOf(char) method.
C# Example
using System; public class StringLastIndexOfTest { public static void Main() { String str = "aa bb cc dd"; Console.WriteLine( str.LastIndexOf('d', 8) ); Console.WriteLine( str.LastIndexOf('b', 8) ); } }The output is
-1
4
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0