You are misunderstanding that particular overload of the LastIndexOf
method.
The docs state the following:
The search starts at a specified character position and proceeds backward toward the beginning of the string.
Note that it says backward
. So, if you start at position 0
, there is no "<"
substring at that position or in front of that position and hence the result is -1
.
In contrast, if you use the overload that takes only the substring, the search will start at the end of the string and hence correctly find the indicated substring.