Hi there!
I have a form with a button and a label.
Can anyone offer some insight as to why the following code snippet gives me
the following error: "Use of unassigned local variable 'path2'? If I remove
the variable all together and assign the label1.text = dialog.Selected Path
then the code works but I don't understand why. I hope someone can shed some
light on the subject. Thanks.
Sean Campbell
private void button1_Click(o bject sender, EventArgs error)
{
string path2;
try
{
FolderBrowserDi alog dialog = new FolderBrowserDi alog();
dialog.ShowNewF olderButton = false;
if (dialog.ShowDia log() == DialogResult.OK )
{
path2 = dialog.Selected Path;
}
label1.Text = path2;
}
I have a form with a button and a label.
Can anyone offer some insight as to why the following code snippet gives me
the following error: "Use of unassigned local variable 'path2'? If I remove
the variable all together and assign the label1.text = dialog.Selected Path
then the code works but I don't understand why. I hope someone can shed some
light on the subject. Thanks.
Sean Campbell
private void button1_Click(o bject sender, EventArgs error)
{
string path2;
try
{
FolderBrowserDi alog dialog = new FolderBrowserDi alog();
dialog.ShowNewF olderButton = false;
if (dialog.ShowDia log() == DialogResult.OK )
{
path2 = dialog.Selected Path;
}
label1.Text = path2;
}
Comment