Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The variable is either undeclared or was never assigned warning

Tags:

c#

.net

winforms

This is the base class:

public class BaseClass : UserControl
{
     protected ListView list;
     protected TreeView tree;
    
     public BaseClass()
     {
         //...
     }
     //...
}

Child class:

public partial class MyClass : BaseClass
{
     public MyClass()
     {
         InitializeComponent();
         this.BackColor = VisualStyleInformation.TextControlBorder;
         this.Padding = new Padding(1);
     }
     //...
}
    
partial class MyClass
{
    //...
        
    private void InitializeComponent()
    {
         this.tree = new System.Windows.Forms.TreeView();
         this.list = new System.Windows.Forms.ListView();
         //...
         this.tree.Location = new System.Drawing.Point(0, 23);
         this.tree.Name = "blablabla";
    }
}

Compiling the classes gives me these warnings:

Warning 1 The variable 'tree' is either undeclared or was never assigned.
Warning 2 The variable 'list' is either undeclared or was never assigned.

What am I doing wrong? These variables are declared in base class and assigned in child class.

like image 999
Romz Avatar asked Sep 09 '12 20:09

Romz


1 Answers

This question lacks an answer, so here goes...

Rebuild Solution then restart Visual Studio worked for me :-)

Thanks to SLaks for his comment above.

Also discussed at:

stackoverflow.com - The variable 'variable_name' is either undeclared or was never assigned.

social.msdn.microsoft.com - The variable 'control_name' is either undeclared or was never assigned.

like image 71
davmos Avatar answered Nov 06 '22 11:11

davmos