简体   繁体   English

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

[英]The variable is either undeclared or was never assigned warning

I have code like this:我有这样的代码:

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

And 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 ?我究竟做错了什么 ? This variable are declared in base class, and assigned in child class.该变量在基类中声明,并在子类中分配。

This question lacks an answer , so here goes... 这个问题缺乏答案 ,所以这里......

Rebuild Solution then restart Visual Studio worked for me :-) Rebuild Solution然后重启Visual Studio为我工作:-)

Thanks to SLaks for his comment above. 感谢SLaks上面的评论。

Also discussed at: 还讨论了:

stackoverflow.com - The variable 'variable_name' is either undeclared or was never assigned. stackoverflow.com - 变量'variable_name'未声明或从未分配。

social.msdn.microsoft.com - The variable 'control_name' is either undeclared or was never assigned. social.msdn.microsoft.com - 变量'control_name'未声明或从未分配过。

I have run into this with the designer and the main cause each time was the fact my solution was set for x64 output.我和设计者都遇到过这个问题,每次的主要原因都是我的解决方案是为 x64 输出设置的。 Currently, the designer CANNOT deal with a control in a solution set for x64, so you need to change it to Any CPU, make your edits, then change it back to x64 to do your running/debugging.目前,设计器无法处理 x64 解决方案集中的控件,因此您需要将其更改为 Any CPU,进行编辑,然后将其更改回 x64 以进行运行/调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 变量未声明或从未分配 - The variable is either undeclared or was never assigned 得到错误变量 <variable name> 要么未申报,要么从未分配 - got error The variable <variable name> is either undeclared or was never assigned 变量'variable_name'要么未声明,要么从未分配过 - The variable 'variable_name' is either undeclared or was never assigned 变量“ control”是未声明的或从未分配过的-除非如此,否则应用程序将进行编译 - The variable 'control' is either undeclared or was never assigned - Except it is, and the application compiles 变量未声明或从未分配,并且重建不起作用 - The variable is either undeclared or was never assigned and rebuilding does not work 未声明或从未分配导致错误“变量”的Windows Forms Designer类继承 - Windows Forms Designer class inheritance causing error 'variable' is either undeclared or was never assigned Winform设计X64不起作用“变量usercontrol1未声明或从未分配” - Winform design X64 doesn't work “The variable usercontrol1 is either undeclared or was never assigned” 变量未声明或从未分配? 和数据读取器无法正常工作? - variable was undeclared or was never assigned? and data reader not working? C#警告:已分配变量但从未使用过 - C# Warning: Variable is assigned but never used “字段从未分配给”警告 - “Field is never assigned to” warning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM