psvavvon

Untitled

May 9th, 2021 (edited)
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Pair
  2. {
  3.     public Pair(int t, double v)
  4.     {
  5.         Time = t;
  6.         Value = v;
  7.     }
  8.    
  9.     public int Time;
  10.     public double Value;
  11. }
  12.  
  13. void Main()
  14. {
  15.     List<Pair> list1 = new() { new(1, 123), new(2, 234), new(3, 345) };
  16.     List<Pair> list2 = new() { new(2, 567), new(3, 678), new(4, 456) };
  17.     List<Pair> list3 = new() { new(1, 789), new(2, 890), new(3, 900) };
  18.  
  19.     var times1 = list1.Select(e => e.Time);
  20.     var times2 = list2.Select(e => e.Time);
  21.     var times3 = list3.Select(e => e.Time);
  22.     var allTimes = times1.Concat(times2).Concat(times3).ToHashSet();
  23.  
  24.     var results = allTimes.Select(t =>
  25.     {
  26.         var value1 = list1.Find(x => x.Time == t)?.Value;
  27.         var value2 = list2.Find(x => x.Time == t)?.Value;
  28.         var value3 = list3.Find(x => x.Time == t)?.Value;
  29.  
  30.         return new { t, value1, value2, value3 };
  31.  
  32.     });
  33.  
  34.     results.Dump();
  35. }
RAW Paste Data