Assign char range/set to array?

  • Thread starter Thread starter John E.
  • Start date Start date
J

John E.

I cannot seem to find the equivilant of assigning a range to an array in c#.
In other languages you can do something like:

@myArray = ("a" .. "z");

or something to that effect. Thus creating an array with 26 indexes from
'a' through 'z'. How is this possible in C#? I *really* don't want to have
to type in all the characters independently for each of my different
character validators.

Any assistance is greatly appreciated.

TIA
-John
 
There is no built in method for this initialization. But you could create
your own char[] creator function like:

char[] CharRange(char start, char end)
{
int size = (end - start) + 1;
char[] chars = new char[size];
for (int i = 0 ; i < size ; i++)
chars = (char)(start + i);
return chars;
}

Then just call:
char[] chars = CharRange('a', 'z');

Another alternative is something like:
char[] chars = "abcdefghijklmnopqrstuvwxyz".ToCharArray();


justin.///
 
Back
Top