Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get a range from an ObservableCollection?

I would like to get a range from an ObservableCollection for the purpose of looping through it and changing a property on those items. Is there an easy built-in way to do this with the ObservableCollection class?

like image 988
Rachel Avatar asked Dec 12 '22 18:12

Rachel


1 Answers

You can use Skip and Take.

System.Collections.ObjectModel.ObservableCollection<int> coll = 
    new System.Collections.ObjectModel.ObservableCollection<int>()
        { 1, 2, 3, 4, 5 };
foreach (var i in coll.Skip(2).Take(2))
{
    Console.WriteLine(i);
}
like image 184
Albin Sunnanbo Avatar answered Jan 04 '23 22:01

Albin Sunnanbo