什么是LINQ ToDictionary和ToLookup之间的区别 [英] What is the difference between LINQ ToDictionary and ToLookup

查看:857
本文介绍了什么是LINQ ToDictionary和ToLookup之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是LINQ ToDictionary和ToLookup之间的区别?他们似乎做同样的事情。

What is the difference between LINQ ToDictionary and ToLookup? They seem to do the same thing.

推荐答案

一个字典是一个1:1的地图(每个键映射到一个值),和一本字典是事后可变(编辑)

A dictionary is a 1:1 map (each key is mapped to a single value), and a dictionary is mutable (editable) after the fact.

一个查找是一个1:许多地图(多图;每个键映射到一个的IEnumerable<> 用该密钥的数值),并且有在 ILookup<没有发生变异;,> 接口。

A lookup is a 1:many map (multi-map; each key is mapped to an IEnumerable<> of the values with that key), and there is no mutate on the ILookup<,> interface.

作为一个方面说明,您可以查询一键查找(通过索引)不存在,你会得到一个空序列。 。做相同的字典,你会得到一个异常

As a side note, you can query a lookup (via the indexer) on a key that doesn't exist, and you'll get an empty sequence. Do the same with a dictionary and you'll get an exception.

所以:?多少记录共享每个键

So: how many records share each key?

看它的过于简化的方式是,查找< TKEY的,TValue> 是的大致相当的一个词典< TKEY的,IEnumerable的< TValue>>

An overly simplified way of looking at it is that a Lookup<TKey,TValue> is roughly comparable to a Dictionary<TKey,IEnumerable<TValue>>

这篇关于什么是LINQ ToDictionary和ToLookup之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆