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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With