First of all the compiler does nothing after you've
compiled your program, that is when you have your exe. Well the
JIT compiler[
^] does, but just forget about that one, just adding it so noone yells at me :P
the reason your program stops running is because it's casting an exception sooner or later as you have no way of knowing that there are no more lines. So sooner or later you'll call
ReadLine
when
c
is at
txtlines.Count - 1
and thus you index into
txtlines[txtlines.Count]
which always result in a
IndexOutOfRangeException
Well You have alot of problems in your code.
0) Naming
c
is not a very saying name, I would call it something along the lines of
_currentLine
you can remove the underscore I use it to emphasize that it's a field and not a local variable.
LinesStr, is also very badly named, What would be expected is all the lines in one string, it should be named LineCount or something along those lines.
1) In your
LinesStr
(LineCount) you return the the line count as a string, bad, bad practice. You should change the return type to
int
and remove
.ToString()
2) EndOfString makes no sense it only returns true of the input is an empty string and this is the source of your immediate problem.
You should return
c >= txtlines.Count