When running my code i put several string on different lines of the textbox but it breaks saying there is a Null Exception Error on "Items.Add(item)" I am not sure why I am getting this error because in visual studio the string in the variable item is not null it contains a return character through so I am not sure if that is an issue.. for example item = "uno\r". Also, Items is a list of strings. Does anyone know why I keep getting this Null Exception?
public List<string> Items;
public void getItemsFromTextBox(TextBox textbox)
{
string[] lines = textbox.Text.Split('\n');
foreach (string item in lines)
{
if (!String.IsNullOrWhiteSpace(item))
Items.Add(item);
}
}
Itemscollection is uninitialized.