Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select the first three elements of a IEnumerable object?

Tags:

c#

ienumerable

That's it. The question is in the title

I was looking for a cleaner way than the using for...break;

thanks

like image 984
Lorenzo Avatar asked Dec 15 '25 18:12

Lorenzo


1 Answers

This should do it!

var items = new List<int>(){ 1, 2, 3, 4, 5 };
var results = items.Take(3);
like image 141
Mark Carpenter Avatar answered Dec 17 '25 08:12

Mark Carpenter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!