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

  • SEARCH
  • Home
  • 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 3399186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:44:26+00:00 2026-05-18T04:44:26+00:00

This situation may be far more complicated than I want it to be, but

  • 0

This situation may be far more complicated than I want it to be, but I am bringing it forth anyway. This is for a game-type design.

The values here are hard coded, but that will not be the case in a real environment.

Basically, there are lists of classes known as Interpreter that contain the appropriate information to translate other things across the program engine. There is a default ‘layout’ for these, but then in many special cases, some of them need to be overridden.

One solution is to just have every instance in every list (this is doable, but I really think it’s redundant and I think a cleaner solution exists) Instead I am wanting to ‘combine’ them, but be able to specify a property to use as an “override”. (full source code available on pastie. I would put it here, but I have been told that putting that much code deters people from answering my questions) : http://www.pastie.org/1276064

public class Program
{
    static void Main()
    {
        var traits = new List<Trait>
        {
            new Trait { Name = "Intellect" },
            new Trait { Name = "Strength" },
            new Trait { Name = "Constitution" }
        };

        var scores = new List<Score>
        {
            new Score { Name = "Beginner", Rank = 1 },
            new Score { Name = "Adept", Rank = 2 },
            new Score { Name = "Expert", Rank = 3 },
            new Score { Name = "Master", Rank = 4 }
        };

        // one sheet will have defaults
        var initial = new Sheet
        {
            Interpreters = new List<Interpreter>
            {
                new Interpreter
                {
                    Trait = traits.Single( s => s.Name == "Intellect" ),
                    Score = scores.Single( s => s.Rank == 1 ),
                    Requirement = 10
                },
                new Interpreter
                {
                    Trait = traits.Single( s => s.Name == "Intellect" ),
                    Score = scores.Single( s => s.Rank == 2 ),
                    Requirement = 20
                },
                new Interpreter
                {
                    Trait = traits.Single( s => s.Name == "Intellect" ),
                    Score = scores.Single( s => s.Rank == 3 ),
                    Requirement = 30
                }
            }
        };

        // other sheets will override some or all of the default
        var advanced = new Sheet
        {
            Interpreters = new List<Interpreter>
            {
                new Interpreter
                {
                    Trait = traits.Single( s => s.Name == "Intellect" ),
                    Score = scores.Single( s => s.Rank == 2 ),
                    Requirement = 15
                },
                new Interpreter
                {
                    Trait = traits.Single( s => s.Name == "Intellect" ),
                    Score = scores.Single( s => s.Rank == 4 ),
                    Requirement = 35
                }
            }
        };

        // combined sheet should have values of default, with the appropriately 'overridden' values of the advanced
    }

In this situation, the combined list should read like…

[0]
 Trait = Intellect,
 Score = 1,
 Requirement = 10
[1]
 Trait = Intellect,
 Score = 2,
 Requirement = 15
[2]
 Trait = Intellect,
 Score = 3,
 Requirement = 30
[3]
 Trait = Intellect,
 Score = 4,
 Requirement = 35

I do know how I could achieve it with this specific instance of course. I can simply write a method that checks the value of the score, etc. But I want a more convention based approach that I can use in a bit more complicated manner. Does anyone have any ideas?

  • 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-18T04:44:26+00:00Added an answer on May 18, 2026 at 4:44 am

    To get the result you described you could use a method like this:

    Sheet Combine(Sheet initial, Sheet advanced)
    {
        Sheet result = new Sheet();
        result.Interpreters = new List<Interpreter>(
            initial.Interpreters.Select(i =>
                advanced.Interpreters.SingleOrDefault(a => a.Score == i.Score) ?? i)
            );
        return result;
    }
    

    I may have the logic wrong for the case when one Sheet contains different Traits, but you didn’t specify how do you want to combine them.

    Also, the design of your code is quite odd. Not every collection has to be a List<T>. Especially in this case, where using Dictionary<K,V> would be much cleaner (and faster) than using Single().

    EDIT

    For your updated version, I like List-based solution more than a LINQ one:

    Sheet Combine(Sheet initial, Sheet advanced)
    {
      var interpreters = new List<Interpreter>(initial.Interpreters);
      foreach (var interpreter in advanced.Interpreters)
      {
        int index = interpreters.FindIndex(x => x.Score == interpreter.Score);
        if (index < 0)
          interpreters.Add(interpreter);
        else
          interpreters[index] = interpreter;
      }
    
      return new Sheet { Interpreters = interpreters };
    }
    

    EDIT 2

    Here is the LINQ solution you asked for:

    Sheet Combine(Sheet initial, Sheet advanced)
    {
      var scores = initial.Interpreters.Select(i => i.Score)
        .Concat(advanced.Interpreters.Select(i => i.Score))
        .Distinct().OrderBy(i => i);
      var interpreters = scores.Select(s =>
        advanced.Interpreters.SingleOrDefault(i => i.Score == s)
        ?? initial.Interpreters.Single(i => i.Score == s));
      return new Sheet { Interpreters = interpreters };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi this may seem like a weird question, but here's my situation: I have
I have this situation: $(#button).toggle(function(){ $(#window).animate({top:'0%'},1000); },function(){ $(#window).animate({top:'-100%'},1000); }); but I need change it
I have this situation where I want to display a list of Administration objects
I know this is a little subjective, but I'm looking into the following situation:
I realize that this question may appear to be a duplicate, but none of
So I know there's a lot of questions regarding this, but so far as
In this situation I have two models, Comment and Score. The relationship is defined
I have this situation: http://jsfiddle.net/bRDgK/3/ In this situation I have a modal dialog with
I came across this situation while migrating our DB from Foxpro to SQL. Below
I have this situation: { float foo[10]; for (int i = 0; i <

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.