Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq skip, take

Tags:

linq

I have a list that has 4 rows. I need to get the value of the 3rd row.

    var result = (from rs in list
                  select rs).Skip(2).First();

Is there a reason why I would want to use a Take(1) in this scenerio as I have seen used.

     var result = (from rs in list
                  select rs).Skip(2).Take(1);
like image 432
Nate Pet Avatar asked Feb 01 '12 23:02

Nate Pet


1 Answers

Take(1) returns an IEnumerable<T> containing one object.
First() returns the object directly.

like image 59
SLaks Avatar answered Nov 03 '22 01:11

SLaks