好的,我在命名空间下创建了一个自定义组件My_Namespace
。然后在代码的某处我试图实时添加我的自定义组件:
public void Some_Method()
{
My_Namespace.My_Custom_Component my_component;
my_component.Location = new System.Drawing.Point(100, 100);
my_component.Name = "my_component";
my_component.Size = new System.Drawing.Size(380, 380);
this.Controls.Add(my_component);
}
但是我收到此错误
错误 CS0165:使用未分配的局部变量“my_component”
我不明白,因为my_component
在我的方法开始时声明了。
有谁知道怎么了?否则如何实时调用自定义组件的好方法?