I have been working on a windows from application abd I seem to have run into a problem where I am getting Index as out of rang of array
when trying to add a text box line to a list:
My current code is as follows:
if (NameTB.Lines.Count() > 0)
for (int i = 1; 1 <= NameTB.Lines.Count(); i++)
nameList.Add(NameTB.Lines[i].Replace(Environment.NewLine, "").Trim());
I have also tried this:
if (NameTB.Lines.Length > 0)
for (int i = 1; 1 <= NameTB.Lines.Length; i++)
nameList.Add(NameTB.Text[i - 1].ToString().Replace(Environment.NewLine, "").Trim());
and
if (NameTB.Lines.Count() > 0)
for (int i = 1; 1 <= NameTB.Lines.Count(); i++)
nameList.Add(Convert.ToString(i).Replace(Environment.NewLine, "").Trim());
Also though the last example does not give the index error but gets stuck in a loop. I have done something like this before but using WPF
and TextBox.GetLineText
but to sure how to achive the same thing in Winforms