What does Collection.Contains() use to check for existing objects?

前端 未结 6 1171
眼角桃花
眼角桃花 2020-12-03 09:34

I have a strongly typed list of custom objects, MyObject, which has a property Id, along with some other properties.

Let\'s say that the

6条回答
  •  半阙折子戏
    2020-12-03 09:59

    You can use IEquatable. Implement this in your class, and then check to see if the T passed to the Equals has the same Id as this.Id. I'm sure this works for checking a key in a dictionary, but I've not used it for a collection.

提交回复
热议问题