I have a generic list of integer and it contains random numbers. How would I select the last n elements from the list using LINQ?
I know can use myList.GetRange(index, count) to get the last n elements from the list. Is there a way to do it in LINQ?
THanks
regards, Balan
var count = myList.Count;
myList.Skip(count-n)
Update:
removed redundant Take.
You could use myList.Reverse().Take(n)
to achieve what you want.
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