I am porting a Delphi application to C#. In one of the units there is a declaration like this:
const
IdentChars = ['a'..'z', 'A'..'Z', '_'];
I did not found similar declaration syntax for C#.
This is the best I could come up with:
char[] identFirstChars; // = ['a'..'z', 'A'..'Z', '_'];
int size = (int)'z' - (int)'a' + 1 + (int)'Z' - (int)'A' + 1 + 1;
identFirstChars = new char[size];
int index = 0;
for(char ch = 'a'; ch <= 'z'; ch = (char)((int)(ch) + 1))
{
identFirstChars[index] = ch;
index++;
}
for (char ch = 'A'; ch <= 'Z'; ch = (char)((int)(ch) + 1))
{
identFirstChars[index] = ch;
index++;
}
identFirstChars[index] = '_';
There must be a more efficient way.
What about this?
Of course, you can generate an array in your code (this probably can be done with much less lines using Enumerable.Range) but I think in your case it doesn’t worth it.