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();
}
}
Hi, in the program above, I want to judge whether there is stuff not read in the console using “str!=null”.
However,the ReadLine() returned a “” to me instead of a null,
and the program can get into the while loop and generate a wrong result.
How can I fix it?
check it for both with the built in method
if it comes back empty they just pressed enter, and you’ve it your sentinel either way, so you can fail on that.