Why can't you use null as a key for a Dictionary?

后端 未结 11 1895
长情又很酷
长情又很酷 2020-12-24 00:33

Apparently, you cannot use a null for a key, even if your key is a nullable type.

This code:

var nullableBoolLabels = new System.Collect         


        
11条回答
  •  南方客
    南方客 (楼主)
    2020-12-24 00:49

    Not using null is part of the contract according to the MSDN page: http://msdn.microsoft.com/en-us/library/k7z0zy8k.aspx

    I guess the reason is that having null as valid value will just complicate the code for no reason.

提交回复
热议问题