I have an object declared as:
private string SourceProgram;
Basically i am trying to parse some stuff using the code below:
private void LabelScan(System.IO.BinaryWriter OutputFile, bool IsLabelScan)
{
if (char.IsLetter(SourceProgram[CurrentNdx]))
{
if (IsLabelScan) LabelTable.Add(GetLabelName(), AsLength);
while (SourceProgram[CurrentNdx] != '\n')
CurrentNdx++;
CurrentNdx++;
return;
}
EatWhiteSpaces();
ReadMneumonic(OutputFile, IsLabelScan);
}
However i get an error on execution:
- SourceProgram[CurrentNdx]
'SourceProgram[CurrentNdx]' threw an exception of
type 'System.IndexOutOfRangeException' char {System.IndexOutOfRangeException}
- base {"Index was outside the bounds of the array."}
System.SystemException {System.IndexOutOfRangeException}
And the Value of CurrentNdx is 46.
What has gone wrong. Is the string variable SourceProgram of length < 46 ?
If yes, how to fix this code?
Yes, this error suggests that SourceProgram has less than 47 characters. That’s pretty much all we can tell you though without seeing the contents of SourceProgram.