foreach Dictionary<>.Values or foreach Dictionary<>

后端 未结 4 1517
忘掉有多难
忘掉有多难 2021-01-07 06:54

I want to know the details of this two styles of iterating Dictionary collections in C#:

Dictionary xydic = new Dictionary

        
4条回答
  •  太阳男子
    2021-01-07 07:41

    Values is not creating a List, no. It's not even pulling the entire set of values into a separate data structure. All it's doing is creating an enumerator that can iterate over the values. It's doing exactly the same thing that happens when you iterate the dictionary directly; the difference is that instead of constructing a KeyValuePair object for each pair of objects, its only giving you one half of the pair. Other than that, the iteration process is the same.

提交回复
热议问题