fix an index error with string output

Had a difficult error message that I was struggling with for a while in Visual Studio. This is a small C# taster example line:

Console.WriteLine("At a height of {1}m and a weight of {2}kg, {3} has a BMI of {4}\n", p1.Height, p1.Weight, p1.Name, p1.ComputeBMI(p1.Height,p1.Weight));

And the error message:

Format exception was unhandled

"Index (zero based) must be greater than or equal to zero and less than the size of the argument list." Wasnt sure what to make of the index, but I had a suspicion it had to do with arrays. Turns at the issue was quite simple. In console.writeline, the assumption is that the arguments start numbering from {0} to {n-1} where there are n arguments. I was starting from 1, thus causing this issue.

No votes yet