Debugging Challenge

Addressing the issue (C#)

Christian Clausen
1 min readMay 4, 2020

Previously on Dr. Lambda’s blog: I have devised a series of debugging challenges, some are easy, some are really hard, all come from real live systems. Good luck!

The Challenge

  • 1 point if you can spot where the error is.
  • +1 point if you can explain why.
  • +2 points if you can explain how to fix it.
int index = addressLine.Length;
for (int i = 0; i < 10; i++)
{
int position = addressLine.IndexOf(i.ToString());
if (position != -1 && position < index)
index = position;
}
string street = addressLine.Substring(0, index).Trim();
string nr = addressLine
.Substring(index, addressLine.Length - index)
.Trim();

--

--

Christian Clausen
Christian Clausen

Written by Christian Clausen

I live by my mentor’s words: “The key to being consistently brilliant is: hard work, every day.”

No responses yet