tags:

views:

174

answers:

1

How to convert Enum to Key,Value Pairs. I have converted it in C# 3.0 .

 public enum Translation
    {
        English,
        Russian,
        French,
        German
    }

   string[] trans = Enum.GetNames(typeof(Translation));

   var v = trans.Select((value, key) =>
   new { value, key }).ToDictionary(x => x.key + 1, x => x.value);

In C# 1.0 What is the way to do so?

+1  A: 

In C# 1...

string[] names = Enum.GetNames(typeof(Translation));

Hashtable hashTable = new Hashtable();
for (int i = 0; i < names.Length; i++)
{
    hashTable[i + 1] = names[i];
}

Are you sure you really want a map from index to name though? If you're just using integer indexes, why not just use an array or an ArrayList?

Jon Skeet
Thanks.Just I finished schooling.Learnig C#.I will follow your advice sir.
Well, specific questions and answers are ideal - but questions related to *small* pieces of code in terms of design, clarity etc are fine. Just don't submit thousands of lines of code in one question :) It also helps if your examples are short and complete, rather than just being part of a big project.
Jon Skeet
Sir, i need very clear answer to my question "C# iteration requesting scenario based example" which i just posted.could you help me ,giving precise example?