-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

1
  • See duplicate. Simply use ToList() on each group instead of the Aggregate() operation seen there. Commented May 14, 2021 at 23:58

1 Answer 1

1
var groupedByTimestamp = objlistA.Concat(objlistB)
    .GroupBy(o => o.timeStamp)
    .Select(g => g.Select(s => s.value).ToList())
    .ToList();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.