关于c#:变量未声明或从未分配过警告

The variable is either undeclared or was never assigned warning

我有这样的代码:

这是基类:

1
2
3
4
5
6
7
8
9
10
11
public class BaseClass : UserControl
{
     protected ListView list;
     protected TreeView tree;

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

子班

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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";
    }
}

警告:

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

我做错什么了?这个变量在基类中声明,并在子类中赋值。


这个问题没有答案,所以这里…

重新生成解决方案,然后重新启动为我工作的Visual Studio:-)

感谢斯莱克斯在上面的评论。

另讨论地点:

stackoverflow.com-变量"variable_name"未声明或从未分配。

social.msdn.microsoft.com-变量"controlu name"未声明或从未分配。