-1

I have a class as below..

public class MyObject
    {
        public DateTime timeStamp { get; set; }
        public int value { get; set; }
    }

I have two lists as below with same timestamp but diff values.. I have tried to show with --> how the data internally is.

IReadOnlyList<MyObject> objlistA --> [{1234,56},{1235,78}....]
IReadOnlyList<MyObject> objlistB --> [{1234,98},{1235,32}....]

I wish to create a List<List<int>> where the values from both objects with same timestamp form the inner list.

Such that my list looks as below..

[[56,98],[78,32]......]

I'm aware that in my last couple of questions, I was unable to convey my problem statement properly. Please do ask to clarify if you have any queries..

Thanks

poke
  • 369,085
  • 72
  • 557
  • 602
Arnab
  • 2,324
  • 6
  • 36
  • 60

1 Answers1

1
var groupedByTimestamp = objlistA.Concat(objlistB)
    .GroupBy(o => o.timeStamp)
    .Select(g => g.Select(s => s.value).ToList())
    .ToList();
Gleb
  • 1,723
  • 1
  • 11
  • 24