相关疑难解决方法(0)

Dictionary中元素的顺序

我的问题是关于枚举字典元素

// Dictionary definition
private Dictionary<string, string> _Dictionary = new Dictionary<string, string>();

// add values using add

_Dictionary.Add("orange", "1");
_Dictionary.Add("apple", "4");
_Dictionary.Add("cucumber", "6");

// add values using []

_Dictionary["banana"] = 7;
_Dictionary["pineapple"] = 7;

// Now lets see how elements are returned by IEnumerator
foreach (KeyValuePair<string, string> kvp in _Dictionary)
{
  Trace.Write(String.Format("{0}={1}", kvp.Key, kvp.Value));
}
Run Code Online (Sandbox Code Playgroud)

枚举的元素将以什么顺序排列?我可以强制命令按字母顺序排列吗?

.net c# ienumerable dictionary

99
推荐指数
6
解决办法
8万
查看次数

Generic Key/Value pair collection in that preserves insertion order?

I'm looking for something like a Dictionary<K,V> however with a guarantee that it preserves insertion order. Since Dictionary is a hashtable, I do not think it does.

Is there a generic collection for this, or do I need to use one of the old .NET 1.1 collections?

.net c# data-structures

30
推荐指数
4
解决办法
3万
查看次数

标签 统计

.net ×2

c# ×2

data-structures ×1

dictionary ×1

ienumerable ×1