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. ToList() or not to List.

ToList() or not to List.

Scheduled Pinned Locked Moved C#
visual-studiocsharpdatabaselinq
7 Posts 4 Posters 19 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I notice that VS Intellisense wants to tag every LINQ query I code with ".ToList()". It is in fact an extra step that imposes unnecessary overhead when all you need is an IEnumerable in the chain. It just gets worse as the "frame rate" increases. While List<> is prefered "internally", it doesn't pay to be reflex "converting" when it isn't necessary. (IMO)

    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

    D L P 3 Replies Last reply
    0
    • L Lost User

      I notice that VS Intellisense wants to tag every LINQ query I code with ".ToList()". It is in fact an extra step that imposes unnecessary overhead when all you need is an IEnumerable in the chain. It just gets worse as the "frame rate" increases. While List<> is prefered "internally", it doesn't pay to be reflex "converting" when it isn't necessary. (IMO)

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      It doesn't "want" to append it. It's just that the "AI" has seen it so much in all of the code in its training repositories that it thinks that's what is most likely to come next.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

      L 1 Reply Last reply
      0
      • D Dave Kreskowiak

        It doesn't "want" to append it. It's just that the "AI" has seen it so much in all of the code in its training repositories that it thinks that's what is most likely to come next.

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I doesn't "want" to but can't help itself? Caught up in the herd mentality? And that makes it "OK"?

        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

        D J 2 Replies Last reply
        0
        • L Lost User

          I doesn't "want" to but can't help itself? Caught up in the herd mentality? And that makes it "OK"?

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          An AI in only as good as the training set it's taught with, so yeah, you could say it's following the heard. I never said that makes it "OK". All I said is what it's doing.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

          1 Reply Last reply
          0
          • L Lost User

            I notice that VS Intellisense wants to tag every LINQ query I code with ".ToList()". It is in fact an extra step that imposes unnecessary overhead when all you need is an IEnumerable in the chain. It just gets worse as the "frame rate" increases. While List<> is prefered "internally", it doesn't pay to be reflex "converting" when it isn't necessary. (IMO)

            "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Just use your best judgement as always. Intellisense helps you type faster (some of the time), but it's no substitute for intelligence. ToList'ing everything all the time is obviously silly.

            1 Reply Last reply
            0
            • L Lost User

              I notice that VS Intellisense wants to tag every LINQ query I code with ".ToList()". It is in fact an extra step that imposes unnecessary overhead when all you need is an IEnumerable in the chain. It just gets worse as the "frame rate" increases. While List<> is prefered "internally", it doesn't pay to be reflex "converting" when it isn't necessary. (IMO)

              "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

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

              It really depends what I want to do with the list. I'll leave it as an enumerable until the point I want to do more than one thing with it. Suppose I wanted to check to see if the list had something in it before I started processing in it - the fact that I'm going to be calling Any and foreach (for example), suggests to me that I should materialise the enumerable and then act on it. If I don't, I'm just going to end up materialising it twice under the covers.

              Advanced TypeScript Programming Projects

              1 Reply Last reply
              0
              • L Lost User

                I doesn't "want" to but can't help itself? Caught up in the herd mentality? And that makes it "OK"?

                "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #7

                lol. Yep. I have certainly seen developers do that. They can't figure out how to do it in the initial clause so they end up processing it in memory. Definitely not a good thing for working with a database. Sigh...unfortunately I have also seen this happen implicitly by the library. I can see it by profiling in SQL Server while running a linq expression. That makes everything horribly wrong. It means I have no way to verify except by profiling everything. I have seen all of the following by profiling. - It dragged the entire table into the app space and then applied the clauses. - It did an in clause by doing a while loop over each in parameter. So 200 separate SQL calls. - It did a join by doing a different SQL call for each table and then joining in memory. None of the above makes me want to ever use linq again.

                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