0

Why this cause a out of range exception

string str="my nam is milad"; /* why this line cuse a out of range error ---------------- */ string tmp=str.Substring(str.Length-4,str.Length-1); Console.WriteLine(tmp);

1st May 2017, 12:17 PM
martin franklin
martin franklin - avatar
1 Resposta
+ 1
you want to get a substring of length str.Length-=13 starting at position str.Length-4. but here the maximum remaining string has only length 4, so you try to read beyond the end of str.
1st May 2017, 12:25 PM
Volker Milbrandt
Volker Milbrandt - avatar