Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Difference between where<>() and where() in linq? [modified]

Difference between where<>() and where() in linq? [modified]

Scheduled Pinned Locked Moved C#
questioncsharplinq
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sri_3464 0
    wrote on last edited by
    #1

    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

    P S 2 Replies Last reply
    0
    • S sri_3464 0

      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

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      • S sri_3464 0

        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

        S Offline
        S Offline
        Scott Dorman
        wrote on last edited by
        #3

        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 of TSource 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

        P 1 Reply Last reply
        0
        • S Scott Dorman

          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 of TSource 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

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          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.

          My blog | My articles | MoXAML PowerToys | Onyx

          S 1 Reply Last reply
          0
          • P Pete OHanlon

            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.

            My blog | My articles | MoXAML PowerToys | Onyx

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #5

            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

            P 1 Reply Last reply
            0
            • S Scott Dorman

              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

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              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.

              My blog | My articles | MoXAML PowerToys | Onyx

              S 1 Reply Last reply
              0
              • P Pete OHanlon

                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.

                My blog | My articles | MoXAML PowerToys | Onyx

                S Offline
                S Offline
                Scott Dorman
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups