Iterating through the Alphabet - C# a-caz

后端 未结 10 1087
無奈伤痛
無奈伤痛 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:49

    just curious , why not just

        private string alphRecursive(int c) {
             var alphabet = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
             if (c >= alphabet.Length) {
                 return alphRecursive(c/alphabet.Length) + alphabet[c%alphabet.Length];
             } else {
                 return "" + alphabet[c%alphabet.Length];
             }
        }
    

提交回复
热议问题