Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code
C#
       foreach (string item in Properties.Settings.Default.DatesEventNames)
           {


Label neweventlabel = new Label();
                   neweventlabel.Content = item;
                   SP1.Children.Add(neweventlabel);

           }

SP1 = stackpanel1

I have this code and I was wondering if I can just have every 3rd line in the stringcollection(DatesEventNames) will be posted, because I don't want all of them posted.

can some one please help me with this?
Posted
Comments
Zoltán Zörgő 2-Jan-13 3:05am    
Count them and check the modulus...
[no name] 2-Jan-13 3:08am    
i don't understand

1 solution

I agree with Zoltán Zörgő, this can be a solution:

C#
int i=0;
foreach (string item in Properties.Settings.Default.DatesEventNames)
{
    if ((i++%3)==0)
    {
        Label neweventlabel = new Label();
        neweventlabel.Content = item;
        SP1.Children.Add(neweventlabel);    
    }

}
 
Share this answer
 
Comments
Zoltán Zörgő 2-Jan-13 3:53am    
Yes, this is what I suggested.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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