Why can't I compare a KeyValuePair with default

后端 未结 6 2031
Happy的楠姐
Happy的楠姐 2020-12-30 19:25

In .Net 2.5 I can usually get an equality comparison (==) between a value and its type default

if (myString == default(string))

However I g

6条回答
  •  再見小時候
    2020-12-30 20:10

    Defaults are pitched at scalar types.

    Ask yourself this question: What does it mean for KVP to have a default value?

    For non-scalars the default is whatever you get from calling the nil constructor. Assuming that KVP Equals performs instance identity comparison, I would expect it to return false since you get a new object each time the constructor is invoked.

提交回复
热议问题