.NET中用于查找字符串键或数字索引的最佳数据结构是什么?

JC *_*bbs 6 .net collections ordereddictionary data-structures

我正在寻找最理想的数据结构(性能和易用性),从中可以通过字符串键或索引检索值.字典不起作用,因为您无法通过索引真正检索.有任何想法吗?

Mit*_*eat 7

你想要OrderedDictionary类.您需要包含System.Collections.Specialized命名空间:

    OrderedDictionary od = new OrderedDictionary(); 
    od.Add("abc", 1); 
    od.Add("def", 2); 
    od.Add("ghi", 3); 
    od.Add("jkl", 4); 

    // Can access via index or key value:      
    Console.WriteLine(od[1]);       
    Console.WriteLine(od["def"]);
Run Code Online (Sandbox Code Playgroud)