Iterating through the Alphabet - C# a-caz

后端 未结 10 1107
無奈伤痛
無奈伤痛 2020-11-29 03:03

I have a question about iterate through the Alphabet. I would like to have a loop that begins with \"a\" and ends with \"z\". After that, the loop begins \"aa\" and count to

10条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 03:54

    The following populates a list with the required strings:

    List result = new List();
    for (char ch = 'a'; ch <= 'z'; ch++){
        result.Add (ch.ToString());
    }
    
    for (char i = 'a'; i <= 'z'; i++)
    {
        for (char j = 'a'; j <= 'z'; j++)
        {
            result.Add (i.ToString() + j.ToString());
        }
    }
    

提交回复
热议问题