私はC#にDelphiアプリケーションを移植しています。ユニットの1つでは、次のような宣言があります。ポートパスカルconst IdentChars = ['a' .. 'z'、 'A' .. 'Z'、 '_'];宣言からC#
const
IdentChars = ['a'..'z', 'A'..'Z', '_'];
C#の宣言構文が見つかりませんでした。
これは私が思い付くことが最高です:
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] = '_';
、より効率的な方法があるに違いありません。
あなたがそれを使用する方法を教えてください。 'char []'だけではありません。 'HashSet'は別です。 –
ここでコンテキストが.netコンテキスト(isvalididentifier)で有効でなければならない場合、おそらくあなたはこの関数を移植するべきではないでしょう。あなたのために書かれた別の同様の関数.NETフレームワークで既に... http://msdn.microsoft.com/en-us/library/system.codedom.compiler.codedomprovider.isvalididentifier.aspxのようなもの –