Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
List of integers
Message
De
12/02/2020 21:52:08
 
 
Information générale
Forum:
C#
Catégorie:
LINQ
Divers
Thread ID:
01673037
Message ID:
01673039
Vues:
51
Thank you Naomi, it was hard but finally I did it, and yes I saw the code that page it also helped me.

John.


>Hi,

>Did you try examples in this

>https://docs.microsoft.com/en-us/dotnet/csharp/linq/group-query-results

?

If this would not help yet, then just Google by "linq group by sum" and see what comes up.

>Hi, I have this doubt about what is the best option to store in memory 2 integer columns, uid and value, I'm getting a list of integers from an Api that returns result as follows:
>
>1  10
>2 2
>2 55
>1 20
>1 30
>3 10
>1 20
>
>I need to convert that to:
>
>1 80
>2 57
>3 10
></code>
>it must be the sum of the second column grouped by column 1.
>I already have a linq to get an unsorted list of the 2 colums:
><code>
>var transact= from data in result
>select new {Name=data.uId, Total=(int)data.Total};
>
>With this I have the first list, now I need to store by uId and sum the Total, any ideas? I have tried with no success List List int, Keyvaluepair and I really don't understand what to do. I need to iterate the list after the linq, adding uid and sum second column each time the uid repeats.
>How can I find an existing uId and sum the total instead of adding always?
>
>var acu=new List<KeyValuePair<int, int>>();
>foreach (var item in transact){
>//here is it good to find the key here and update total? or use another kind of structure or dictionary?
>    acu.Add(new KeyValuePair<int, int>(item.uId, item.Total));
>}
>
>
>TIA.
John Harold Belalcázar Lozano
Associate Director Of Development
http://www.belvicto.co/
jhbelalc@gmail.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform