There is no particular reason for doing such thing. It's a nightmare :)
The
(Convert.ToInt32(c[0]) >= 65 && Convert.ToInt32(c[0]) <= 90 || Convert.ToInt32(c[0]) == 95 || Convert.ToInt32(c[0]) >= 97 && Convert.ToInt32(c[0]) <= 122)
code snippet is trying to check if the first character of a char array or a string
is letter or underscore. But it is awful... :(
Such conversions are not needed at all. It would have been that simple:
(c[0]>='A' && c[0]<='Z') || (c[0]>='a' && c[0]<='z') || c[0]=='_'
... or even simpler with Char.IsLetter...
But as I see in the revision history, the rest of the code is also full of nonsense...
As the mehod's identifier is
CheckIdentifier
, it should do what it tells, but as C# for example is accepting unicode and digits in the identifiers, it is not C# identifier tester.
For C# it would be that simple:
public static bool CheckIdentifier(String i) {
CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");
return provider.IsValidIdentifier (i);
}