I am looking for an efficient way of getting a list with all English (latin) characters.
A, B, C, .... , Z
I really don't want a constructor like this:
// nasty way to create list of English alphabet
List<string> list = new List<string>();
list.Add("A");
list.Add("B");
....
list.Add("Z");
// use the list
...
If you are curius on how is this usable, I am creating a bin-tree mechanism.
You can do this with a for
loop:
List<char> list = new List<char>();
for (char c = 'A'; c <= 'Z'; ++c) {
list.Add(c);
}
If you want a List<string>
instead of a List<char>
use list.Add(c.ToString());
instead.
Note that this works only because the letters A - Z occur in a consecutive sequence in Unicode (code points 65 to 90). The same approach does not necessarily work for other alphabets.
Here:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
This string is a list of characters.
Use either ToCharArray
or the LINQ ToList
to convert to an enumerable of your choice, though you can already access each item through the Chars
indexer of the string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With