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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:33:44+00:00 2026-05-22T19:33:44+00:00

I have the following list class Programm { public static void Main(string[] args) {

  • 0

I have the following list

class Programm
    {

        public static void Main(string[] args)
        {
           List<Service> Services =new List<Service>
            {
                  new Service
                      {
                        Name = "name1",
                        Prices = new List<BEPrice>
                           {
                            new BEPrice
                              {
                               Price = 120,
                               Quantity = 3
                              } 

                            }
                      },
               new Service
                   {
                     Name = "name2",
                     Prices = new List<BEPrice>
                       {
                         new BEPrice
                           {
                            Price = 123,
                            Quantity = 3
                           } 

                     }
                },

              new Service
                {
                 Name = "name3",
                 Prices = new List<BEPrice>
                 {
                   new BEPrice
                    {
                      Price = 100,
                      Quantity = 3
                    } 

                  }
              },

              new Service
               {
                 Name = "name4",
                 Prices = new List<BEPrice>
                 {
                  new BEPrice
                   {
                    Price = 900,
                    Quantity = 8
                  } 

                 }
             }
         };






    }


    public class Tariff
    {

        public string Name { get; set; }
        public List<BEPrice> Prices { get; set; }
    }


    public class Service
    {

        public string Name { get; set; }
        public List<BEPrice> Prices { get; set; }
        public Tariff Tariff;
    }


    public class BEPrice
    {

        public decimal Price { get; set; }
        public int Quantity { get; set; }

    }

I want a result as

Tariff-1 -> Name - "blabla", Prices =  { 
            Price1 = {Price = 343, Quantity = 3}, 
            Price2 = {Price = 900, Quantity = 8}   }

The tariff first price Price1 343 is a sum of 100, 120, 123 for 3 (Quantity) month.

Here is my unsuccessful attemp

 foreach (var groupedPrices in Services.Select(s => s.Prices.GroupBy(p => p.Quantity)))
            {

                foreach (var p in groupedPrices.Select(x => x.Key))
                    Console.WriteLine(p);


                foreach (var price in groupedPrices)
                {

                    _prices.AddRange(price.Select(p => p));
                }

            }
  • 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-22T19:33:46+00:00Added an answer on May 22, 2026 at 7:33 pm

    Not sure what is name blabla, but this is how you can get prices part

    var prices = Services
        .SelectMany(arg => arg.Prices)
        .GroupBy(arg => arg.Quantity)
        .Select(arg => new { Price = arg.Sum(x => x.Price), Quantity = arg.Key })
        .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: class Program { static void Main(string[] args) { string
I have the following code: public class Events extends ListActivity { //... private static
I have the following collection contract defined: [CollectionDataContract(Name = Centres)] public class Centres :
Take a look at the following program: class Test { List<int> myList = new
I have the following class definition and the main(). Can someone please point me
suppose I have the following class: class MyInteger { private: int n_; public: MyInteger(int
We have the followig code: [Serializable] public class Class1 { [XmlElement(description)] public string Description
Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>
I have the following data structure (a list of lists) [ ['4', '21', '1',
I have the following method in my code: private bool GenerateZipFile(List<FileInfo> filesToArchive, DateTime archiveDate)

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.