Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4609950
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:03:42+00:00 2026-05-22T01:03:42+00:00

I have a situation where I have lists of objects that have to be

  • 0

I have a situation where I have lists of objects that have to be merged. Each object in the list will have a property that explains how it should be treated in the merger. So assume the following..

enum Cascade {
  Full,
  Unique,
  Right,
  Left
}

class Note {
  int Id { get; set; }
  Cascade Cascade { get; set; }
  // lots of other data.
}

var list1 = new List<Note>{
 new Note {
   Id = 1,
   Cascade.Full,
   // data
 },
 new Note {
   Id = 2,
   Cascade.Right,
   // data
 }
};
var list2 = new List<Note>{
  new Note {
   Id = 1,
   Cascade.Left,
   // data
  }
};
var list3 = new List<Note>{
  new Note {
    Id = 1,
    Cascade.Unique,
    // data similar to list1.Note[0]
  }
}

So then, I’ll have a method …

Composite(this IList<IList<Note>> notes){
  return new List<Note> {
      notes.SelectMany(g => g).Where(g => g.Cascade == Cascade.All).ToList()
      // Here is the problem... 
      .SelectMany(g => g).Where(g => g.Cascade == Cascade.Right)
      .Select( // I want to do a _LastOrDefault_ )
      // continuing for the other cascades. 
  }
}

This is where I get lost. I need to do multiple SelectMany statements, but I don’t know how to. But this is the expected behavior.

Cascade.Full

The Note will be in the final collection no matter what.

Cascade.Unique

The Note will be in the final collection one time, ignoring any duplicates.

Cascade.Left

The Note will be in the final collection, First instances superseding subsequent instances. (So then, Notes 1, 2, 3 are identical. Note 1 gets pushed through)

Cascade.Right

The Note will be in the final collection, Last instance superseding duplicates. (So Notes 1, 2, 3 are identical. Note 3 gets pushed trough)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:03:43+00:00Added an answer on May 22, 2026 at 1:03 am

    I think you should decompose the problem in smaller parts. For example, you can implement the cascade rules for an individual list in a seperate extension method. Here’s my untested take at it:

    public static IEnumerable<Note> ApplyCascades(this IEnumerable<Note> notes)
        {
            var uniques = new HashSet<Note>();
            Note rightToYield = null;
            foreach (var n in notes)
            {
                bool leftYielded = false;
    
                if (n.Cascade == Cascade.All) yield return n;
                if (n.Cascade == Cascade.Left && !leftYielded)
                {
                    yield return n;
                    leftYielded = true;
                }
                if (n.Cascade == Cascade.Right)
                {
                    rightToYield = n;
                }
                if (n.Cascade == Cascade.Unique && !uniques.Contains(n))
                {
                    yield return n;
                    uniques.Add(n);
                } 
            }
    
            if (rightToYield != null) yield return rightToYield;
        } 
    }
    

    This method would allow to implement the original extension method something like this:

        List<Note> Composite(IList<IList<Note>> notes)
        {
            var result = from list in notes
                         from note in list.ApplyCascades()
                         select note;
            return result.ToList();
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my situation: I got a list of objects. Each object has a
I have 2 Lists of differnt objects used in different contexts. Each list is
I have this situation where I want to display a list of Administration objects
Here is my situation: I have one table that contains a list of drugs
I have a method that searches a list of objects based on some of
I'm using Protobuf-net. Suppose I have a list of Gizmo objects serialized and that
The situation is as follows: I have a ViewModel that has a property that's
I have a situation where I'm creating a number of IDisposable objects that encapsulate
I have a situation where I get a reference to an object that I
I have method that parses a list of String records into objects and returns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.