I'm trying to add numbers per unique names from two list inputs as shown in the example below using C#.
Inputs
numbers: 1, 2, 3, 4, 5
names: A, B, A, B, C
The two lists that I'm trying to get as outputs are:
Outputs
uniqueNames: A, B, C
numbersPerName: 4(1+3), 6(2+4), 5
I can get the unique names from a list, but how can I add numbers per unique name after the code below?
HashSet<string> nameSet = new HashSet<string>();
for (int i = 0; i < names.Count; i++){
nameSet.Add(names[i]);
}
uniqueNames = nameSet;
Thank you for any help in advance!