Click here to Skip to main content
Rate this: bad
good
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);
and
Student stud = context.Students.select();
 
and how can we use select????
Posted 18-Jan-13 2:30am

1 solution

Rate this: bad
good
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);
 
Reference: http://msdn.microsoft.com/en-us/library/bb548891.aspx[^]
and
http://msdn.microsoft.com/en-us/library/bb535050.aspx[^]
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 808
1 OriginalGriff 493
2 sanket saxena 329
3 Tadit Dash 315
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,990
1 OriginalGriff 7,349
2 Peter Leow 5,003
3 Abhinav S 4,003
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid