C#关联数组 [英] C# associative array

查看:1511
本文介绍了C#关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用一个Hashtable,但本质上,哈希表是不排序,我需要把一切都为了我加入他们的(因为我要拉出来以相同的顺序)。 Forexample如果我这样做:

I've been using a Hashtable, but by nature, hashtables are not ordered, and I need to keep everything in order as I add them (because I want to pull them out in the same order). Forexample if I do:

pages["date"] = new FreeDateControl("Date:", false, true, false);
pages["plaintiff"] = new FreeTextboxControl("Primary Plaintiff:", true, true, false);
pages["loaned"] = new FreeTextboxControl("Amount Loaned:", true, true, false);
pages["witness"] = new FreeTextboxControl("EKFG Witness:", true, true, false);

当我做一个foreach我希望能够得到它的顺序:

And when I do a foreach I want to be able to get it in the order of:

pages["date"]  
pages["plaintiff"]  
pages["loaned"]  
pages["witness"] 

我怎样才能做到这一点?

How can I do this?

推荐答案

我相信.NET有<一个href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.ordereddictionary.aspx"><$c$c>OrderedDictionary类处理这个。它不是通用的,但它可以作为一个体面的哈希表的替代品 - 如果你不关心严格的类型安全

I believe that .NET has the OrderedDictionary class to deal with this. It is not generic, but it can serve as a decent Hashtable substitute - if you don't care about strict type safety.

我已经写了解决这个班,我愿意共享一个通用的包装。

I've written a generic wrapper around this class, which I would be willing to share.

<一个href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.ordereddictionary.aspx">http://msdn.microsoft.com/en-us/library/system.collections.specialized.ordereddictionary.aspx

这篇关于C#关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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