Saturday, 17 August 2013

While loop warns of always true since value of type 'int' is never equal to 'null' of type int

While loop warns of always true since value of type 'int' is never equal
to 'null' of type int

I'm new to C#, working through some examples in the C# Head First book and
trying to apply what I've learned in a practical manor. I'm trying to read
in a text file with the following code:
private StreamReader upload;
private void Form1_Load(object sender, EventArgs e)
{
if (File.Exists(@"C:\Users\Recon 5\Desktop\ToDo.txt"))
{
upload = new StreamReader(@"C:\Users\Recon 5\Desktop\ToDo.txt");
while (upload.Peek() != null)
{
currentTasks.Items.Add(upload.ReadLine());
}
upload.Close();
}
}
The above code provides the intended result, adding items into a list box
from a text file. What I haven't been able to ID/understand is why the
argument getting passed into my while loop is giving me the following
warning "The result of the expression is always 'true' since a value of
type 'int' is never equal to 'null' of type 'int'? I've tried looking in
the windows library for a response......understanding the API is a task in
its own right.
I guess what I'm looking for is helpful pointers to either guide my search
or resources to assist me in discovering the answer myself. I'm sure there
might be a better way to write this task but given where I'm at with my
understanding of the language I feel it important to use and understand
the tools I have learned thus far, in this case the while loop. I wanted
to say thanks in advance.

No comments:

Post a Comment