Difference between where<>() and where() in linq? [modified]
-
i have a basic question in linq. Lets say i have a list of student collection List<Student> lstStudents = new List<Student>(); Now when i use the where method, i can either specify List<Student> lstFilteredStudents = lstStudents.where<Student>(...); or i can specify List<Student> lstFilteredStudents = lstStudents.where(...); Now my question is wat is the difference between calling these two methods internally?
modified on Wednesday, March 3, 2010 6:45 AM
-
i have a basic question in linq. Lets say i have a list of student collection List<Student> lstStudents = new List<Student>(); Now when i use the where method, i can either specify List<Student> lstFilteredStudents = lstStudents.where<Student>(...); or i can specify List<Student> lstFilteredStudents = lstStudents.where(...); Now my question is wat is the difference between calling these two methods internally?
modified on Wednesday, March 3, 2010 6:45 AM
None really. The first one is explicitly specifying that the where clause is working against a generic of type Student, where the second version will infer it.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
i have a basic question in linq. Lets say i have a list of student collection List<Student> lstStudents = new List<Student>(); Now when i use the where method, i can either specify List<Student> lstFilteredStudents = lstStudents.where<Student>(...); or i can specify List<Student> lstFilteredStudents = lstStudents.where(...); Now my question is wat is the difference between calling these two methods internally?
modified on Wednesday, March 3, 2010 6:45 AM
As far as LINQ is concerned, there is no difference between either of those calls. In fact, there is only one version of that Where method which is generic and looks like
Where<TSource>(Func<TSource, int, bool> predicate))
. In your first call, you are explicitly stating the type to be used in place ofTSource
and in the second one you are letting the compiler infer the type from the type of the collection.Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
As far as LINQ is concerned, there is no difference between either of those calls. In fact, there is only one version of that Where method which is generic and looks like
Where<TSource>(Func<TSource, int, bool> predicate))
. In your first call, you are explicitly stating the type to be used in place ofTSource
and in the second one you are letting the compiler infer the type from the type of the collection.Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
Welcome back Scott. I take it the book writing has gone well.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Welcome back Scott. I take it the book writing has gone well.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Thanks Pete! Good to be back! Yes, the book writing has gone very well. Four chapters left to be tech reviewed and then the actual publishing process starts. Should be on the shelves in a few months!
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
Thanks Pete! Good to be back! Yes, the book writing has gone very well. Four chapters left to be tech reviewed and then the actual publishing process starts. Should be on the shelves in a few months!
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
Cool. I bet you're glad to have your life back.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Cool. I bet you're glad to have your life back.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Yes. The entire family is glad. :)
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]
Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai