Eventhandle !!!
-
When I am declare "private Label[,] life = new Label[20, 20];" And "life[i,j].Click += new System.EventHandler(ClickLaBel)" A problem was occured : "Error 1 Use of unassigned local variable 'j'" I don't know why ? Can somebydy help me ! :confused::confused::confused: Sorry for my english. Thank for all support !
-
When I am declare "private Label[,] life = new Label[20, 20];" And "life[i,j].Click += new System.EventHandler(ClickLaBel)" A problem was occured : "Error 1 Use of unassigned local variable 'j'" I don't know why ? Can somebydy help me ! :confused::confused::confused: Sorry for my english. Thank for all support !
breakvn wrote:
Use of unassigned local variable 'j'
J doesn't have a value when you are registering the event. First assign a value for j (and i).
The need to optimize rises from a bad design.My articles[^]
modified on Thursday, January 8, 2009 11:26 AM
-
When I am declare "private Label[,] life = new Label[20, 20];" And "life[i,j].Click += new System.EventHandler(ClickLaBel)" A problem was occured : "Error 1 Use of unassigned local variable 'j'" I don't know why ? Can somebydy help me ! :confused::confused::confused: Sorry for my english. Thank for all support !
Did you assign Label instances in your array? Initializing the array initializes all members to null.
-
When I am declare "private Label[,] life = new Label[20, 20];" And "life[i,j].Click += new System.EventHandler(ClickLaBel)" A problem was occured : "Error 1 Use of unassigned local variable 'j'" I don't know why ? Can somebydy help me ! :confused::confused::confused: Sorry for my english. Thank for all support !
breakvn wrote:
Use of unassigned local variable 'j'
means j has no value yet (it is local, hence not initially zero), yet you are already reading and using it. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
breakvn wrote:
Use of unassigned local variable 'j'
J doesn't have a value when you are registering the event. First assign a value for j (and i).
The need to optimize rises from a bad design.My articles[^]
modified on Thursday, January 8, 2009 11:26 AM
-
You could try something like (don't mind about the typos):
Label tempLabel;
for (int i = 0; i<20; i++) {
for (int j = 0; j<20; j++) {
tempLabel = new Label();
tempLabel.Click += new System.EventHandler(ClickLabel)
life[i,j] = tempLabel;
}
}The need to optimize rises from a bad design.My articles[^]