如何在List中使用exists函数。在 C# 中搜索列表中的项目时出错

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

我正在创建树,我想搜索 NIC 是否存在于列表中,但是当我这样做时 list.Exists(nic) 它给出错误请帮助

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);
            }
        }
    }
}

虽然你的问题遗漏了很多信息,但我想你需要的是:

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