变量未声明或从未分配警告

时间:2012-09-09 20:38:38

标签: c# .net winforms

我有这样的代码:

这是基类:

public class BaseClass : UserControl
{
     protected ListView list;
     protected TreeView tree;

     public BaseClass()
     {
         //...
     }
     //...
}

儿童班

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";
    }
}

警告:

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

我做错了什么?此变量在基类中声明,并在子类中指定。

1 个答案:

答案 0 :(得分:2)

这个问题缺少答案,所以这里......

重建解决方案,然后重启Visual Studio 为我工作: - )

感谢SLaks上面的评论。

还讨论了:

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.