Okay, I created a custom component under the namespace My_Namespace. Then somewhere in the code I’m trying to add my custom component in real-time:
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);
}
However I get this error
Error CS0165: Use of unassigned local variable ‘my_component’
I don’t understand because my_component is declared at the start of my method.
Anyone know what’s wrong? Otherwise how is the good way to call a custom component in real-time?
My guess is it should be instead:
You cannot use an uninitialized variable.