How to refer to items in Dictionary<string, string> by integer index?
- by Edward Tanguay
I made a Dictionary<string, string> collection so that I can quickly reference the items by their string identifier.
But I now also need to access this collective by index counter (foreach won't work in my real example).
What do I have to do to the collection below so that I can access its items via integer index as well?
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);
}
}
}