I have a class:
public class LED
{
public System.Windows.Forms.Label lbl;
public LED(System.Windows.Forms.Label lblLED)
{
lbl = lblLED;
}
public void blink(System.Drawing.Color color, int pattern)
{
// ...
}
}
and I'm creating an instance of it in a top-class:
public LED LED1 = new LED(lblLED1); // (1)
public void update_LED(Label lbl, double i)
{
//LED LED1 = new LED(lblLED1); // (2)
}
in case (2) it allows me to pass lblLED1 inside the constructor, but in case (1) it says:
A field initializer cannot reference the non-static field, method, or property 'lblLED1'
What's the problem?