I have a List<T>
like shown below, the list can contain nulls, below is just an example.
contactEntries = new List<ContactEntries>();
contactEntries.Add(new ContactEntries() { isPrimary = true, contactPerson = ceo, telephone = telephone, telephone1 = telephone1, address = address, postalCode = postalCode, city = city, email = email, role = (Roles)role, contry = (Countries)country });
And here are the class
public class ContactEntries
{
[DisplayName("Primary:")]
public bool isPrimary { get; set; }
[DisplayName("Contact person:")]
public string contactPerson { get; set; }
[DisplayName("Telephone:")]
public string telephone { get; set; }
[DisplayName("Telephone 1:")]
public string telephone1 { get; set; }
[DisplayName("Address:")]
public string address { get; set; }
[DisplayName("Postal code:")]
public string postalCode { get; set; }
[DisplayName("City:")]
public string city { get; set; }
[DisplayName("Email:")]
public string email { get; set; }
[DisplayName("Role:")]
public Roles role { get; set; }
[DisplayName("Country:")]
public Countries contry { get; set; }
}
public enum Roles
{
CEO = 0,
IT = 1
}
public enum Countries
{
Denmark = 0,
Norway = 1,
Sweden = 2
}
Below is where I need to check for nulls. Note that this is a form, and the class (_contactEntries) is in another class, therefore there are some accessibility problems
private void WizardCreateOrder_Finish(object sender, EventArgs e)
{
// Add client
MySQL.Clients.Insert.Client(_orgNo, _companyName, _ceo, _companyType, _country, _leadId, _countryCode, out int clientId);
// Here I need to check for null
// Add contact persons
foreach (var entry in _contactEntries)
{
MySQL.Clients.ContactPerson.Insert.ContactPerson(entry.contactPerson, entry.telephone, entry.telephone1, entry.address, entry.postalCode,
entry.city, entry.email, _country, _countryCode, entry.role.ToString(),
entry.isPrimary.ToString(), DateTime.Now, clientId, _leadId);
}
}
My question is: how can I check all these elements inside the list for null in a way that I don't have to check them one by one, but for example use linq to output a boolean that tells if there are nulls or not.