The whole 'A' + number is converting the number from 0-25 to A-Z.
Aa library letter mod#
The basic idea here is that the least significant digit is the number mod the base, then we divide the number by the base and modding it again is the next significant digit. Private static char digitToChar(int digit) Here's that helper method: private static string convertToLetter(int counter) We'll start with a helper method, it will take an integer, convert it to base 26, and then map each digit to a letter of the alphabet. Just imagine that 0 is "A", 1 is "B", 25 is "Z", 1 0 (one zero) is "BA" etc. What you're doing is counting in base 26.
Okay, so I've had some fun and some headbashing working through this one, and this is what I've come up with: Note that these function are "inifnite" (I haven't tested stackoverflow issues) so don't forget to provide a limitation Var items = "ABCD".Foo(ch => ch.ToString(), (str, ch) => str + ch).Take(100) // "A" to "AADD" again Yield return combineSelector(temp, item) Public static IEnumerable Foo(this IEnumerable source,įoreach (var temp in source.Foo(resultSelector, combineSelector)) Var items = "ABCD".Foo().Take(100) // "A" to "AADD"Īnd same kind of thing but with generic (with required additional parameters to handle transformations) Public static IEnumerable Foo(this string alphabet) You could use a recursive function using iterator syntax to achieve this (and allowing to pass in the "alphabet" you want.