Windows Phone Developers

Sunday, August 24, 2008

Use of unassigned local variable 'name'

The C# compiler does not allow the use of uninitialized variables. If the compiler detects the use of a variable that might not have been initialized, it generates CS0165.

string Sample;

Nullable <bool> FlagComplete = null;

if (FlagComplete.HasValue)

{

MessageBox.Show(Sample);

}

Use new to create an instance of an object or assign a value

string Sample = "";

Nullable <bool> FlagComplete = null;

if (FlagComplete.HasValue)

{

MessageBox.Show(Sample);

}

else




If you want to have null for the variable Sample, declare it as Nullable ()
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment:

  1. Can also do something like...

    bool? FlagComplete = null;
    if(FlagComplete.HasValue)
    {

    }

    ReplyDelete

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005