static void Main()
{
string str;
str = Console.ReadLine();
while (str != null)//HERE!
{
str = str.Remove(0, 1);
str = str.Remove(str.Length - 1, 1);
string[] value = str.Split(',');
int[] intval = new int[value.Length];
for (int i = 0; i < value.Length; ++i)
{
bool re = int.TryParse(value[i], out intval[i]);
Console.WriteLine(intval[i]);
}
str = Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
嗨,在上面的程序中,我想判断控制台中是否有使用"str!= null"读取的内容.
但是,ReadLine()向我返回一个""而不是null,程序可以进入while循环并生成错误的结果.
我该如何解决?
while(!string.IsNullOrEmpty(str))
Run Code Online (Sandbox Code Playgroud)
使用内置方法检查它们
如果它回来是空的,他们只需按下进入,你就可以使用它作为你的哨兵,所以你可以失败.
| 归档时间: |
|
| 查看次数: |
4410 次 |
| 最近记录: |