Paolo Amato
Paolo Amato

Reputation: 61

Sorting a List<object[]> by datetime

I Have this list:

List<object[]> lstMessaggi = new List<object[]>();

A sample element in this list is an array of 3 objects:

1)a string

2)a datetime

3)a string

My question is:how can i order "lstMessaggi" by ascending Datetime values?

Upvotes: 0

Views: 244

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 415600

First of all, this data structure seems like a really bad idea. It's calling out for a class definition, or at very least a tuple.

But, assuming the elements in the list are consistent, you can do this:

List<object[]> lstMessaggi = new List<object[]>();
lstMessaggi = lstMessaggi.OrderBy(m => (DateTime)m[1]).ToList();

Upvotes: 3

Related Questions