how can I get the top 30 items in a list in C# and add it to a new list?
I have a list of about a 1000 items, and want to create new lists, of about 30 items each, and then somehow bind the lists to listbox
Use LINQ
Take()
method:
var top30list = source.Take(30).ToList();
Add using System.Linq
at the top of your file to make it work.
everybody is saying linq so i'll show example without linq:
List<object> newList = new List<object>();
for(int i=0 ; i < 30 ; i++)
newList.Add(oldList[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