C# — Need an IDictionary implementation that will allow a null key

前端 未结 6 1886
时光取名叫无心
时光取名叫无心 2020-12-11 01:20

Basically, I want something like this:

Dictionary dict = new Dictionary();
dict.Add(null, \"Nothing\");
dict.Add(         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 01:44

    No need for a different implementation of Dicionary.

    Take a look at my answer here: https://stackoverflow.com/a/22261282/212272

    You will also be able to keep your dictionary strongly typed:

    var dict = new Dictionary, string>();
    dict[1] = "one int";
    dict[null] = "null int";
    
    Assert.AreEqual("one int", dict[1]);
    Assert.AreEqual("null int", dict[null]);
    

提交回复
热议问题