Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating an array of letters in the alphabet

Tags:

c#

alphabet

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.

like image 326
Helephant Avatar asked Nov 24 '08 15:11

Helephant


People also ask

How do you create an array of alphabets in C++?

void createMine(int i); string alphabet[26] = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };

How do you store characters in an array?

To store the words, a 2-D char array is required. In this 2-D array, each row will contain a word each. Hence the rows will denote the index number of the words and the column number will denote the particular character in that word.


2 Answers

I don't think there is a built in way, but I think the easiest would be

  char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); 
like image 129
Bob Avatar answered Sep 25 '22 02:09

Bob


C# 3.0 :

char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray(); foreach (var c in az) {     Console.WriteLine(c); } 

yes it does work even if the only overload of Enumerable.Range accepts int parameters ;-)

like image 28
Pop Catalin Avatar answered Sep 25 '22 02:09

Pop Catalin