Search code examples
c#asp.netlambdaexistsdatareader

How to use exists function in List. having error while searching an item in list in c#


I am creating a tree and I want to search if an NIC is present in the list or not but when I do list.Exists(nic) it gives error please help

List<PeopleInvolved> broList = new List<PeopleInvolved>();
List<PeopleInvolved> allInvolved = new List<PeopleInvolved>();
string value = "null";

foreach (var person in allInvolved)
{
    conn.Open();
    nic = person.NIC;
    using (dr3 = cmd5.ExecuteReader())
    {
        if (!dr3.Read())
        {
            dr3.Close();

            if (broList.Exists(nic))
            {
                valueTable.Add(nic, 6);
            }
        }
    }
}

Solution

  • Although your question misses a lot of information, I think what you need is:

    if (broList.Exists(p=>p.NIC==nic))