Click here to Skip to main content
15,905,914 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
var split1 = str.Split(new[] { '~', ',', '!' });

 for (int i = 0; i < split1.Count(); i += 3)
            {
Label[] LabelName = new Label[split1.Count()];
                   LabelName[i].Name = split1[i].ToString();
}


C#
LabelName.Location = new Point(Convert.ToInt32(split1[i + 1]), Convert.ToInt32(split1[i + 2]));
Posted
Updated 8-Jan-16 18:13pm
v3

This is the easiest error to figure out. All you have to do is inspect variable contents when the code stops for an exception or hits a breakpoint you set.

The debugger is there to show you just how much you don't know about your own code and data.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Jan-16 3:17am    
5ed. It's funny that, these days, a couple of members keep trolling some very correct answers on everyday basis. Perhaps the pattern is: too short or too general. How wrong! Yes, I know you don't care about it. You are perfectly right.
—SA
It's because LabelName is an emtry array, you should initialize each element in the array before you can access its properties. Try this:

C#
var split1 = str.Split(new[] { '~', ',', '!' });
 
Label[] LabelName = (from sp in split1
                     select new Label{
                     Name = sp}).ToArray();
 
Share this answer
 
Comments
Sathish km 9-Jan-16 0:17am    
'string' does not contain a definition for 'Location' and no extension method 'Location' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?

now getting error....
Sergey Alexandrovich Kryukov 9-Jan-16 3:19am    
This code sample has a syntax bug, but "Location" is not mentioned anywhere. If it's a bug, it's your bug. :-)

Your LabelName is array, so it cannot have a member Location, only the array element has it. Problem solved.
But above, you report a different error not shown in your code sample. Now you try to find another non-existing member, String.Location. Do you want to have Location in all types? :-)

—SA
Sathish km 9-Jan-16 5:05am    
yes
Sergey Alexandrovich Kryukov 9-Jan-16 5:44am    
(Sign...)
Philippe Mori 10-Jan-16 19:55pm    
Good start even though not complete as OP probably want to set location of each labels.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900