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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:56:16+00:00 2026-05-29T16:56:16+00:00

I need to aggregate some array values from APIs in a background processing job

  • 0

I need to aggregate some array values from APIs in a background processing job in c#. The number of APIs can in theory be infinite but will probably never be more than 10.

The APIs return a simple list with UserID and Value. To use the data in my application I need to sum all values for each distinct UserID.

Example-data from two APIs:

From API 1:

[1, 240] (Note: The data is organized as [UserID, Value])
[2, 160]
[3, 12568]
[4, 1780]
[...]

From API 2:

[1, 10]
[2, 10]
[3, 10]
[4, 10]
[...]

Desired result:

[1, 250]
[2, 170]
[3, 12578]
[4, 1790]
[...]

How do I, in the most efficient way make this one desired list where the values for each UserID has been added to each other?

I’ve been looking at Matrixes which seems to be a way but I can’t figure out how to do add values without also adding the UserIDs to each other?

(I realize it can be solved with some nested loops but I’m looking for a better way);

Note: The UserID’s are not sequential.

  • 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-29T16:56:16+00:00Added an answer on May 29, 2026 at 4:56 pm

    Using Dictionary<int,int> will probably be faster than anything you can cook up in any other way, even with lookup of whether UserId is already contained as key.

    ie:

    var results = Dictionary<int,int>();
    foreach (var api in apis)
        foreach(var value in api.GetValues())
            if (!result.HasKey(value.UserID))
                result[value.UserId] = value.Value;
            else
                result[value.UserId] += value.Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get some aggregate values from different tables, but my problem is
I have a problem were i need to aggregate some vectors in order to
I need an aggregate sum for a table column (grouped by other columns), but
I need to extract some management information (MI) from data which is updated in
I need to make some aggregates using TClientdataset . In SQL these aggregates can
I need to export data from a SQL database (some groups use SQL Server,
I need to aggregate an array of objects. I would assume using RegEx to
I am creating a custom reporting app in C# and need to aggregate some
I have a cron job I need to run every 7 days to aggregate
I am trying to extract some checkboxes values into an array. My problem is

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.