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. LINQ: Remove first entry of groups in a list

LINQ: Remove first entry of groups in a list

Scheduled Pinned Locked Moved C#
csharplinqtutorialquestion
14 Posts 4 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.
  • OriginalGriffO OriginalGriff

    Try:

    var x = list.GroupBy(g => g.Key).Select(grp => grp.Skip(1)).SelectMany(i => i);

    Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

    B Offline
    B Offline
    BillWoodruff
    wrote on last edited by
    #5

    You need a small tweak to get a one-off instance like 'baz in the result:

    var x = list.GroupBy(g => g.Key).Select(grp =>
    grp.Count() == 1
    ? grp
    : grp.Skip(1)).SelectMany(i => i);

    «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

    OriginalGriffO 1 Reply Last reply
    0
    • B BillWoodruff

      You need a small tweak to get a one-off instance like 'baz in the result:

      var x = list.GroupBy(g => g.Key).Select(grp =>
      grp.Count() == 1
      ? grp
      : grp.Skip(1)).SelectMany(i => i);

      «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #6

      Yes, but his original question specifically excluded "baz".

      Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      B 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Yes, but his original question specifically excluded "baz".

        Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #7

        I tear my hair out, throw myself at your lotus feet, and beg mercy while singing [^] :omg: I'm such a sucker for a stray 'baz :wtf: Been a very weird day !

        «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

        OriginalGriffO L 2 Replies Last reply
        0
        • B BillWoodruff

          I tear my hair out, throw myself at your lotus feet, and beg mercy while singing [^] :omg: I'm such a sucker for a stray 'baz :wtf: Been a very weird day !

          «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #8

          Never any need for that Bill - you are Forgiven[^] of course. (And I love Sharon's voice)

          Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          B 1 Reply Last reply
          0
          • B BillWoodruff

            I tear my hair out, throw myself at your lotus feet, and beg mercy while singing [^] :omg: I'm such a sucker for a stray 'baz :wtf: Been a very weird day !

            «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #9

            Please stop singing immediately. this is supposed to be a serious forum. ;P

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            B 1 Reply Last reply
            0
            • L Luc Pattyn

              Please stop singing immediately. this is supposed to be a serious forum. ;P

              Luc Pattyn [My Articles] Nil Volentibus Arduum

              B Offline
              B Offline
              BillWoodruff
              wrote on last edited by
              #10

              Okay, got it ... I'm switching to screaming :wtf:

              «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

              L 1 Reply Last reply
              0
              • B BillWoodruff

                Okay, got it ... I'm switching to screaming :wtf:

                «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #11

                That would be fine in Q&A :cool:

                Luc Pattyn [My Articles] Nil Volentibus Arduum

                OriginalGriffO 1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  Never any need for that Bill - you are Forgiven[^] of course. (And I love Sharon's voice)

                  Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                  B Offline
                  B Offline
                  BillWoodruff
                  wrote on last edited by
                  #12

                  lovely voice, reminds me a little of Sarah Brightman. thanks, Bill

                  «One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    That would be fine in Q&A :cool:

                    Luc Pattyn [My Articles] Nil Volentibus Arduum

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #13

                    Only when I have finished banging my head on the desk.

                    Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    L 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      Only when I have finished banging my head on the desk.

                      Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #14

                      Are you at it again, wasn't this stretch day for you? :confused:

                      Luc Pattyn [My Articles] Nil Volentibus Arduum

                      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