> >> i want to use c# to generate a list of alphabet e.g.
> A B C ... AA AB AC AD ... AAB ... ZZZZY ... ZZZZZ >> any suggestion will be greatly appreciated.
I don't see why this has to involve recursion.
First decide exactly what you're doing. I think the following is the
pattern you have in mind:
(1) If the string does not end in Z, then change its last letter to the next
letter in the alphabet.
Thus A is followed by B, AA is followed by AB, BLITHERA is
followed by BLITHERB, etc.
(2) If the string *does* end in Z, then, starting from the end, work back
until you find a letter that is not Z, and change it to the next letter in
the alphabet; then replace all the letters after it with A.
Thus AZZ is followed by BAA.
(3) But if you get all the way to the beginning and have all Z's, then
change it to all A's with one more letter.
Thus ZZZ is followed by AAAA.
At least I *think* that's what you have in mind. Is it? If so, it should
be easy to do with StringBuilder (which is mutable, unlike String) and some
simple program logic.
Steps (2) and (3) can be consolidated because, starting from the end, you're
replacing Z's with A's.
P.S. Be sure to acknowledge me when you turn in your homework... if this is
homework.
--
----------------------------------------------------------------------------
---------
Michael A. Covington, Associate Director
Artificial Intelligence Center, The University of Georgia
http://www.ai.uga.edu/~mc