int? test;
try
{
test = (int?) Int32.Parse ("7");
} catch {}
if (test == null)
Console.WriteLine("test is null!");
else
Console.WriteLine("test = {0}", test);
I am have some code that does something VERY similar to this, same idea really... Creating a variable, trying to initialize it, then test to see if the initialization was a success.
Visual Studios is giving me an error saying " Use of unassigned local variable 'test' ", which is kind of annoying, this is easily fixed by setting the first line to:
int? test = null;
but I am curious what the difference between the two lines are, because the compiler really seems to care. And to the best of my knowledge, the two lines do the same thing.