gpt4 book ai didi

c# - 如何列出所有拉丁(英文字母)字符?

转载 作者:太空狗 更新时间:2023-10-29 20:44:41 33 4
gpt4 key购买 nike

我正在寻找一种获取包含所有英文(拉丁文)字符的列表的有效方法。

A, B, C, .... , Z

我真的不想要这样的构造函数:

// nasty way to create list of English alphabet
List<string> list = new List<string>();
list.Add("A");
list.Add("B");
....
list.Add("Z");

// use the list
...

如果您对它的用途感到好奇,我正在创建一个 bin-tree 机制。

最佳答案

您可以使用 for 来做到这一点循环:

List<char> list = new List<char>();
for (char c = 'A'; c <= 'Z'; ++c) {
list.Add(c);
}

如果你想要一个List<string>而不是 List<char>使用 list.Add(c.ToString());相反。

请注意,这仅适用于字母 A - Z 在 Unicode 中以连续序列出现(代码点 65 到 90)。同样的方法不一定适用于其他字母表。

关于c# - 如何列出所有拉丁(英文字母)字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8459620/

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