Click here to Skip to main content
11,790,387 members (65,255 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET4.0
please define the difference between

Student stud = context.Students.First(i => i.Roll_No == 1);
Student stud =;

and how can we use select????
Posted 18-Jan-13 2:30am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I believe you mean the Select(Func) vs First(Func) signature, as there is no parameter free signature of Select.
Well, first of all, First iterates the IEnumerable and stops as it's condition is satisfied. This means that, no matter the size of the collection, on the first occurrence that "Func" returns true, it'll stop and return the item that was being iterated.
Select(Func), on the other hand, returns another collection (IEnumerable) wich may or may not be the same underlying type as the original one. That's because Select works as a "conversor" (projects an item into another item). This also means it'll iterate through all the collection, and it'll return a second and unreferenced IEnumerable. That's really useful when you need to convert a collection or when u need to project a property of all the items of a collection into another one, for example:

var lista = new List<Tuple<int, string>>();
IEnumerable<int> ids = lista.Select(a => a.Item1);


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 315
1 ppolymorphe 219
2 Richard MacCutchan 158
3 Jochen Arndt 95
4 Maciej Los 90
0 OriginalGriff 1,114
1 Maciej Los 825
2 KrunalRohit 686
3 CPallini 611
4 ppolymorphe 610

Advertise | Privacy | Mobile
Web01 | 2.8.1509028.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100