ObservableCollection.Contains() Doesn't Work Correctly

前端 未结 4 1372
时光说笑
时光说笑 2021-01-13 00:55

Consider the following:

class Bind
{
    public string x { get; set; }
    public string y { get; set; }
}
public partial class MainWindow : Window
{
    pub         


        
4条回答
  •  长情又很酷
    2021-01-13 01:42

    Because "a" != "a". At least, not always.

    Contains() will check memory addresses, not the actual contents. You cannot insert the same object twice, and "a" isn't the same object as "a" (at least, not here).

提交回复
热议问题