I have this bit of code, which should be self explanatory:
_item.Distance = Decimal.Round(dDistanceDec, 2);
if (_item.Distance < 5)
{
tempItems.Add(_item);
}
}
tempItems.OrderBy(i => i.Distance).ToList().ForEach(z => nearby.Items.Add(z));
(The bottom curly bracket closes a foreach loop if it makes a difference)
I am trying to limit the number of results to 10 in the 'nearby' listbox. I am a bit confused as it needs to sort them in order first of distance, but by doing that it is adding the items to the 'nearby' listbox. So where would the limiting code go?
tempItems.OrderBy(i => i.Distance)
.Take(10)
.ToList()
.ForEach(z => nearby.Items.Add(z));
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