Search code examples
c#visual-studio-2005

C# codes to get a list of strings like A to Z?


How can I get a list of strings from "A:" to "Z:" in C#? Something like this:

List<string> list = new List<string>();
for (int i = 0; i < 26; i++)
{
   list.Add(string.Format("{0}:", Convert.ToChar('A' + i));
}

Sorry I don't have VS available for verification right now to verify. By the way, is there web site available to interactive test snip of codes?


Solution

  • Well, not counting missing ')' at the end of list.Ad.... line, everything is ok, altough you could write it using a bit shorter notation

    list.Add((char)('A' + i) + ":");