c# List.Contains() Method Returns False

后端 未结 9 1866
梦毁少年i
梦毁少年i 2021-01-28 06:04

In the code block below I would expect dictCars to contain: { Chevy:Camaro, Dodge:Charger }

But, dictCars comes back empty. Because this line returns false each time it

9条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 06:44

    Your car class needs to implement interface IEquatable and define an Equals method, otherwise the contains method is comparing the underlying references.

提交回复
热议问题