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 6768233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:03:04+00:00 2026-05-26T15:03:04+00:00

I have class Reward which i keep user money per game. I have two

  • 0

I have class Reward which i keep user money per game.
I have two list somehow I need to concate. I write sample lists and desired result below.

public class Reward
{
    public int Game { get; set; }
    public int User { get; set; }
    public int Money { get; set; }

    public Reward Merge(Reward p)
    {
       return new Reward { Game = this.Game, User = this.User, Money = this.Money + p.Money};
    }
}

    IList<Reward> list1 = new List<Reward>();
    list1.Add(new Reward {Game = 1, User = 1, Money = 10});
    list1.Add(new Reward { Game = 1, User = 2, Money = 20 });
    list1.Add(new Reward { Game = 1, User = 3, Money = 30 });


    IList<Reward> list2 = new List<Reward>();
    list2.Add(new Reward { Game = 2, User = 1, Money = 15 });
    list2.Add(new Reward { Game = 2, User = 2, Money = 25 });
    list2.Add(new Reward { Game = 2, User = 4, Money = 35 });

Result List should be

User Money
1    25
2    45
3    30
4    35

I try

IList<Reward> listConcat = list1.Concat(list2)
                .GroupBy(u=> u.User)
                .Select(???)
                .ToList();

but how?

  • 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-26T15:03:04+00:00Added an answer on May 26, 2026 at 3:03 pm

    You were on the right track with GroupBy, this should do the job:

    IEnumerable<Reward> result =
        from r in list1.Concat(list2)
        group r by r.User into groupedRewards
        select new Reward
        {
            Game = 0,   //what game to use?
            User = groupedRewards.Key,
            Money = groupedRewards.Sum(r => r.Money)
        };
    

    EDIT: Same thing with lambda expression:

    IEnumerable<Reward> result = list1.Concat(list2)
        .GroupBy(u => u.User)
        .Select(g => new Reward
        {
            Game = 0,  //what game to use?
            User = g.Key,
            Money = g.Sum(r => r.Money)
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class A, which exposes an event. an object of class B subscribed
I have class that represents users. Users are divided into two groups with different
I have class A and list of A objects. A has a function f
I have a two classes, a controller called AppController and a class called URLDelegate
I have built a component library that includes an executive class which does work
I have a class ShipmentsCollection that inherits ObservableCollection which contains shipment objects (entities). This
I have a Flex Spark dropdownList in which I need to show the Provider
I have a generic list class that implements a particular interface. The list items
I have class A: public B { ...} vector<A*> v; I want to do
I have class Fred { public: void inspect() const {}; void modify(){}; }; int

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.