use of unassigned local variable
From: Ropo (Ropo_at_discussions.microsoft.com)
Date: 09/28/04
- Next message: Marilyn: "Uploading to an area outside of the web server."
- Previous message: Morten Wennevik: "Re: string question"
- Next in thread: Paul Yanzick: "Re: use of unassigned local variable"
- Reply: Paul Yanzick: "Re: use of unassigned local variable"
- Reply: Jon Skeet [C# MVP]: "Re: use of unassigned local variable"
- Reply: James Curran: "Re: use of unassigned local variable"
- Reply: C# Learner: "Re: use of unassigned local variable"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 28 Sep 2004 13:03:09 -0700
Newbie:
I am writing code to read an xml file. I want two values from the document
so I want to save them as I am reading through the elements. I want to
reference them (using Console.WriteLine) after I complete the loop. When I
compile I get the "use of unassigned local variable".
What am I doing wrong?
stripped down code:
static void Main()
{
string Msg;
try
{
// Open an XML file
XmlTextReader reader = new XmlTextReader("...");
while ( reader.Read() )
{
if (reader.NodeType == XmlNodeType.Whitespace)
continue;
if (reader.NodeType != XmlNodeType.EndElement )
{
Msg = reader.Value;
}
if (reader.HasAttributes)
{
reader.MoveToFirstAttribute();
}
}
}
catch (Exception e)
{
Console.WriteLine ("Exception: {0}", e.ToString());
}
Console.WriteLine(Msg);
}
- Next message: Marilyn: "Uploading to an area outside of the web server."
- Previous message: Morten Wennevik: "Re: string question"
- Next in thread: Paul Yanzick: "Re: use of unassigned local variable"
- Reply: Paul Yanzick: "Re: use of unassigned local variable"
- Reply: Jon Skeet [C# MVP]: "Re: use of unassigned local variable"
- Reply: James Curran: "Re: use of unassigned local variable"
- Reply: C# Learner: "Re: use of unassigned local variable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|