Click here to Skip to main content
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 3: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 DamithSL 375
1 Sergey Alexandrovich Kryukov 217
2 OriginalGriff 210
3 Peter Leow 135
4 Uma Shankar Patel 80
0 OriginalGriff 7,380
1 DamithSL 5,359
2 Sergey Alexandrovich Kryukov 4,944
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514

Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
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