I have two lists of the following class:
public class KeyValues
{
public int Key { get;set;}
public List<double> DoubleList { get;set;}
}
var list1 = new List<KeyValues>();
list1.Add (new KeyValues(){Key = 33, DoubleList = new List<double>(){2.3,2.4,2.5}});
list1.Add (new KeyValues(){Key = 34, DoubleList = new List<double>(){3.3,3.4,3.5}});
list1.Add (new KeyValues(){Key = 35, DoubleList = new List<double>(){4.3,4.4,4.5}});
var list2 = new List<KeyValues>();
list2.Add (new KeyValues(){Key = 33, DoubleList = new List<double>(){20.3,20.4}});
list2.Add (new KeyValues(){Key = 34, DoubleList = new List<double>(){30.3,30.4}});
list2.Add (new KeyValues(){Key = 35, DoubleList = new List<double>(){40.3,40.4}});
I would like to combine those into a new list by mathing the keys and combining the sub lists. So the result should be:
list3 = [
[33, {2.3,2.4,2.5,20.3,20.4}]
[34, {3.3,3.4,3.5,30.3,30.4}]
[35, {4.3,4.4,4.5,40.3,40.4}]
]
Of course I can iterate over the keys, but isn't there a much better (faster) linq solution for this?