how to check if object already exists in a list

前端 未结 9 1810
梦谈多话
梦谈多话 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:12

    Simply use Contains method. Note that it works based on the equality function Equals

    bool alreadyExist = list.Contains(item);
    

提交回复
热议问题