Generating an array of letters in the alphabet

前端 未结 14 1637
粉色の甜心
粉色の甜心 2020-11-28 03:53

Is there an easy way to generate an array containing the letters of the alphabet in C#? It\'s not too hard to do it by hand, but I was wondering if there was a built in way

14条回答
  •  执笔经年
    2020-11-28 04:03

    Note also, the string has a operator[] which returns a Char, and is an IEnumerable, so for most purposes, you can use a string as a char[]. Hence:

    string alpha = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";
    for (int i =0; i < 26; ++i)
    {  
         Console.WriteLine(alpha[i]);
    }
    
    foreach(char c in alpha)
    {  
         Console.WriteLine(c);
    }
    

提交回复
热议问题