This is kind of a beginner's question but the code I am looking at is in production and I don't want to break anything. So, just in case: isn't
is equivalent to just
(Except for the potential ArgumentOutOfRangeException.)
Yes, it will be exactly the same.
Looks like it to me. I can't see any reason for writing it like that.
Let's see what that actually means with some numbers:
"My groovy test string".Substring(0, 2).Length == "My".Length = 2
"My groovy test string".Substring(4, 2).Length == "ro" = 2
As you say, if startIndex + Length > length of the string, or startIndex isn't in the string then an ArgumentOutOfRangeException is thrown
So yes, as all of the potential other cases throw an exception.
My suspicion is the author didn't know that the edge case (when startIndex + length > end of string) throws an exception.