我需要能够通过索引检索键和值,获取大小。我需要通过插入对元素进行排序。一个键应该匹配一个值。我尝试过的集合(及其问题):NameValueCollection-允许一对多链接。我猜这会导致不必要的开销。OrderedDictionary–无法通过索引检索键。编辑:有人指出在C#中不存在这样的等价物。在链接的问题中,答案指向一个示例实现的论坛,该论坛似乎已关闭。有人可以提供示例实现吗?编辑2:System.Net的CookieCollection似乎是我所需要的。这如何影响更大的尺寸(元素数量)?我写了这篇文章,过去对我来说效果很好。如果您发现错误,请告诉我。以上就是C#学习教程:C#等价LinkedHashMap分享的全部内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注——usingSystem;使用System.Collections.Generic;类LinkedHashMap{字典>>D=新字典>>();链表>LL=新链表>();publicUthis[Tc]{get{返回D[c].Value.Item1;}set{if(D.ContainsKey(c)){LL.Remove(D[c]);}D[c]=newLinkedListNode>(Tuple.Create(value,c));LL.AddLast(D[c]);}}publicboolContainsKey(Tk){returnD.ContainsKey(k);}publicUPopFirst(){varnode=LL.First;LL.Remove(节点);D.Remove(node.Value.Item2);返回node.Value.Item1;}publicintCount{get{returnD.Count;}}}classLinkedHashMapTest{publicstaticvoidTest(){varlhm=newLinkedHashMap();lhm['a']=1;lhm['b']=2;lhm['c']=3;Console.WriteLine(lhm['a']);Console.WriteLine(lhm['b']);Console.WriteLine(lhm['c']);控制台.WriteLine(lhm.PopFirst());Console.WriteLine(lhm.PopFirst());Console.WriteLine(lhm.PopFirst());}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如有转载请注明出处:
