-2

If I take:

Dictionary<int,string> mydictionary = MyList.Where(x=> x.id == myid).ToDictionary(x => x.id, x=> x.string);

and the list Where does not return any values (none found matching those parameters), what happens to my dictionary?

I ask because I can't check if (mydictionary==null) as mydictionary cannot be null.

I'm sure you're asking "Well why don't you test it yourself?", but I don't currently have access to my development environment.

4

2 回答 2

2

结果是一个Dictionary<int, string>带有 的实例Count == 0,即与

Dictionary<int, string> mydictionary = new Dictionary<int, string>();
于 2013-02-21T22:19:01.787 回答
1

你会得到空的(没有KeyValuePairDictionary<int,string>对象。 ToDictionary扩展方法创建新Dictionary对象并添加元素。

于 2013-02-21T22:18:37.210 回答