开发者

Can I just ask in the loop(foreach) condition

You can create the same design but without the condition (if) ?

开发者_运维百科foreach (var item in ListItems)
{
    if(item.IsChecked)
    {
        //
    }
}

for example(not worked example):

foreach (var item in ListItems(=>IsCheked))
{
    //only IsChecked
}

c#-2.0 - not use linq


I think this is what you're looking for:

foreach (var item in ListItems.Where(i => i.IsChecked)) {
    /// ...
}


C# 3 and Framework 3.5:

foreach(var item in ListItems.Where(x => x.IsChecked))

C# 2 , Framework 2.0 (assuming ListItems is a List)

foreach(<type> item in ListItems.FindAll(delegate(x) { return x.IsChecked; }))

C# 3, Framework 2.0 (if you're using visual studio 2008 or later but targeting 2.0 framework) The lambda syntax and var keyword can be compiled, but there is no System.LINQ library to refer to.

foreach(var item in ListItems.FindAll(x => x.IsChecked))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜