为什么查找一成不变的在C#中? [英] Why is Lookup immutable in C#?

查看:120
本文介绍了为什么查找一成不变的在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

词典,你不能用一个元素添加一个构建一个查找。你碰巧知道原因吗?

Unlike Dictionary, you cannot construct a Lookup by adding elements one by one. Do you happen to know the reason?

查找就像多重映射在C ++中;我们为什么不能修改它在C#中?如果我们真的不能,怎样才能构建在C#多重映射数据结构?

Lookup is just like multimap in C++; why can't we modify it in C#? If we really can't, how can we construct a multimap data structure in C#?

推荐答案

查找 ILookup 分别介绍LINQ,通常需要比功能更强大的方法的一部分该框架的其他方面。我个人的事实,即查找是(至少在公开场合)不变的 - 我期待的more不可改变的集合是可用的

Lookup and ILookup were introduced as part of LINQ, which generally takes a more functional approach than other aspects of the framework. Personally I like the fact that Lookup is (at least publicly) immutable - and I'm looking forward to more immutable collections being available.

如果你想创建自己的multimap中的数据结构,只是保持一个词典< TKEY的,列表与LT; TValue>> 什么类似。你可能想看看我的 Edulinq实施的查找 一些示例代码。

If you want to create your own multimap data structure, just maintain a Dictionary<TKey, List<TValue>> or something similar. You might want to look at my Edulinq implementation of Lookup for some sample code.

这篇关于为什么查找一成不变的在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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