how to check if object already exists in a list

前端 未结 9 1786
梦谈多话
梦谈多话 2020-11-28 05:41

I have a list

  List myList

and I am adding items to a list and I want to check if that object is already in the list.

9条回答
  •  难免孤独
    2020-11-28 06:00

    If it's maintainable to use those 2 properties, you could:

    bool alreadyExists = myList.Any(x=> x.Foo=="ooo" && x.Bar == "bat");
    

提交回复
热议问题