gpt4 book ai didi

c# - 端口 pascal const IdentChars = ['a' 。 .'z' , 'A' 。 .'Z' , '_' ];对 C# 的声明

转载 作者:太空狗 更新时间:2023-10-29 20:59:40 25 4
gpt4 key购买 nike

我正在将 Delphi 应用程序移植到 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] = '_';

必须有更有效的方法。

最佳答案

IdentChars 是一个集合,它在 C# 中没有直接等价物(真的有点痛苦)。其次,IdentChars 是一组 Ansi 字符,而不是 Unicode 字符,所以要小心。因此,最好在“移植”之前查看它是如何使用的,因为您需要的功能内置于 Deplhi 编译器中,您必须自己用 C# 编写代码。

关于c# - 端口 pascal const IdentChars = ['a' 。 .'z' , 'A' 。 .'Z' , '_' ];对 C# 的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6320501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com