C#WPF - stringcollection中的每三行 [英] C# WPF - every third line in a stringcollection

查看:93
本文介绍了C#WPF - stringcollection中的每三行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

this is my code

       foreach (string item in Properties.Settings.Default.DatesEventNames)
           {


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

           }



SP1 = stackpanel1



我有这个代码,我想知道我是否可以在stringcollection(DatesEventNames)中发布每个第3行,因为我不希望所有这些都发布。



有人可以帮我这个吗?


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?

推荐答案

我同意ZoltánZörgő的说法,这可以是一个解决方案:



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

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);    
    }

}


这篇关于C#WPF - stringcollection中的每三行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆