[英]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.