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 to do this.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
C# 3.0 :
yes it does work even if the only overload of Enumerable.Range accepts int parameters ;-)
Surprised no one has suggested a yield solution:
Example:
I wrote this to get the MS excel column code (A,B,C, ..., Z, AA, AB, ..., ZZ, AAA, AAB, ...) based on a 1-based index. (Of course, switching to zero-based is simply leaving off the
column--;
at the start.)You could do something like this, based on the ascii values of the characters:
(See the table here.) You are just casting from the int value of the character to the character value - but, that only works for ascii characters not different languages etc.
EDIT: As suggested by Mehrdad in the comment to a similar solution, it's better to do this:
This casts the A character to it's int value and then increments based on this, so it's not hardcoded.
I don't think there is a built in way, but I think the easiest would be