<分区>
这是正确的吗?
string a;
a = Console.ReadLine();
for (int i = 0; a[i] != '\0'; i++)
{
Console.WriteLine(a[i]);
}
标签 c#
<分区>
这是正确的吗?
string a;
a = Console.ReadLine();
for (int i = 0; a[i] != '\0'; i++)
{
Console.WriteLine(a[i]);
}
最佳答案
不,这是不正确的,因为 C# 字符串通常不以 NUL 字符结尾。
您需要使用 i < a.Length
终止循环,而不是通过查看数组。
关于C# 字符串表现得像 char 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20220480/