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. LINQ
  4. Group By (another question)

Group By (another question)

Scheduled Pinned Locked Moved LINQ
databasecomdata-structureshelptutorial
1 Posts 1 Posters 1 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

    A while back I posted a question[^] and got an answer[^] that worked for that situation. However, the situation has changed (as it always does) and I am wondering if anyone can help solve this. I have an array (no longer a matrix) of items with an Index(int) and an IsAcceptable flag. I want to group all items that are NOT acceptable next to each other with some items that are acceptable depending on a value used to compare to the index. For example (simple)

    int x = 0;
    Collection = new CustomCollection()
    {
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = false},
    new CustomObject(){Index = x++, IsAcceptable = false},
    new CustomObject(){Index = x++, IsAcceptable = false},
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = true},
    }

    This would be an array of 10 elements where items with index 2,3,and 4 are flagged as not acceptable. They are to be grouped. That part can be done with the solution to my previous question. However, I want to pass in to the comparer a value. For example 1 and then Group 1--> Indecies of 1,2,3,4, and 5. Now for the complex situation that must also be handled.

    int x = 0;
    Collection = new CustomCollection()
    {
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = false},
    new CustomObject(){Index = x++, IsAcceptable = false},
    new CustomObject(){Index = x++, IsAcceptable = false},
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = false},
    new CustomObject(){Index = x++, IsAcceptable = true},
    new CustomObject(){Index = x++, IsAcceptable = true},
    }

    In this case the

    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