C#关联数组数组

由网友(清风晓星尘)分享简介:我一直在使用一个Hashtable,但本质上,哈希表是不排序,我需要把一切都为了我加入他们的(因为我要拉出来以相同的顺序)。 Forexample如果我这样做:I've been using a Hashtable, but by nature, hashtables are not ordered, and I n...

我一直在使用一个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有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.

http://msdn.microsoft.com/en-us/library/system.collections.specialized.ordereddictionary.aspx

阅读全文

相关推荐

最新文章