我发了一个词典<string, string>
收集,以便我可以通过他们的字符串标识快速参考项目。如何通过整数索引引用Dictionary <string,string>中的项目?
但我现在还需要访问这个集体由指数计数器(的foreach不会在我的真实的例子工作)。
我必须对下面的集合做些什么以便我可以通过整数索引访问它的项目呢?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestDict92929
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, string> events = new Dictionary<string, string>();
events.Add("first", "this is the first one");
events.Add("second", "this is the second one");
events.Add("third", "this is the third one");
string description = events["second"];
Console.WriteLine(description);
string description = events[1]; //error
Console.WriteLine(description);
}
}
}
到底我在找什么,谢谢 – 2010-03-08 15:33:56