The documentation[
^] is a little confusing - the overload you're calling simply says that it returns the index of the character, if found, or
-1
otherwise.
However, looking at the other overloads, they include the additional information:
"Returns startIndex
if value
is an ignorable character."
Looking at
the source of the overload you're calling[
^], you can see it simply calls the other overload, passing in
source.Length - 1
as the
startIndex
.
Since the value you're looking for is an ignorable character, the method therefore returns
source.Length - 1
- ie:
5
.
This seems like an odd implementation choice to me. I'd expect it to return
-1
in this case. But it is at least correct according to the documentation. :)