Well...look at your code, and what you are asking it to do. Use teh debugger - it'll help you understand.
What do you have in
str
when you arrive at the loop?
Nothing - a blank (empty) string.
So the
while
test compares an empty string with a fixed string "end" and returns true because they are not the same, and it enters the loop.
So you get the length of the string. And because the string is empty, it contains no characters, so it's length is zero.
So then you tell the system to remove the character before the start of the string:
str.Remove(len - 1, 1);
0 - 1, 1
-1, 1
And it goes "Do what? You can't remove characters from there!" and throws an exception. Probably, it throws an "Argument out of range" exception because it's trying to access the string as an array and all arrays in C# start with 0 - so any negative number is illegal as an array index.
What do you do to fix it? Well, you could check if the string is empty and not enter the loop - or you could read a string to process from somewhere and ensure that what you are trying to process will work...