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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:05:02+00:00 2026-06-14T08:05:02+00:00

This question is a slightly modified version of Convert List<T> to Dictionary with strategy

  • 0

This question is a slightly modified version of Convert List<T> to Dictionary with strategy

I have List < DTO > where DTO class looks like this,

private class DTO
    {
        public string Name { get; set; }
        public int Count { get; set; }
    }

I create objects and add it to List.

var dto1 = new DTO { Name = "test", Count = 2 };
var dto2 = new DTO { Name = "test", Count = 3 };
var dtoCollection = new List<DTO> {dto1, dto2};

Now my requirement is I need to create a List from the dtoCollection where Name field should be unique across the entire List.

For example, if you convert the above dtoCollection to the required List from, the resultant list should be like:

List < DTO > count should be 1;

The object inside the list should be a single DTO with Name as “test” and Count as 5

Where Count is obtained from summing up the Count fields in all DTO’s whose Name fields are same

  • 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-06-14T08:05:03+00:00Added an answer on June 14, 2026 at 8:05 am
    var newList = dtoCollection.GroupBy(d => d.Name)
                 .Select(g => new DTO(){ Name=g.Key, Count=g.Select(d => d.Count).Sum()})
                 .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question which is slightly similar to this question on stackoverflow std::cin.clear()
I know this question has been done but I have a slightly different twist
OK, this is a slightly weird question. We have a touch-screen application (i.e., no
I have a question that is similar to this SO question , but slightly
I have a question that is similar to this SO question , but slightly
This question seems to have been asked before, but I feel like my situation
This question has been asked before ( link ) but I have slightly different
This is a slightly tricky question. I am using NSDateFormatter on the iPhone but
Apologies if this is a slightly noob question, but looking to clarify my thoughts
i know this has been asked here . But my question is slightly different.

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.