Currently have a list that you are able to add customer details to through user input. later in the software I then use linq to search the list in order to find if the customer details already exist in the list. I currently have an if statement (listed below) that takes the return value from linq and displays if the customer has details already stored on the list.
Customer cust = finder.list.where(c => c.ID.ToString() == textBox.txt).FirstOrDefault();
if(cust.ID == null)
{
lstDisplay.items.add("Customer details not stored")
}
The issue I am having is that the program crashes once it reaches the if statement with the error: 'Object reference not set to an instance of an object.'
train was null.
how to I handle null being returned.
If null is returned to the value train.ID I want to compare it to null like I have in the if statement. If it is null then I want to be able to display the message box Like I have done