-1

I am using foreach loop to get generic list items which iterates all items, but I want to get certain items, with a condition. I am doing it like following:

 foreach (FilesToProcessDataModels item in ListfilesToProcess)
            {
                if (item.IsChecked)
                {
                    //file operations
                }
            }

Is there any way that i can do it without if statement, to iterate the data where item.IsChecked==true in foreach loop.

4

2 回答 2

4

在哪里使用

var foo = ListfilesToProcess.Where(i => i.IsChecked);
于 2013-09-04T15:19:02.470 回答
4

您可以使用 Linq Where

var checkedItems = ListfilesToProcess.Where(i => i.IsChecked);
foreach (FilesToProcessDataModels item in checkedItems)
{
    // file operations
}
于 2013-09-04T15:18:00.443 回答