Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have List<t> that has data :
June 19
May 5
January 3

All strings. How can I sort it like this :
January 3
May 5
June 19

because I will use it in a chart.

VB
'sorting
  Dim date_1 = date_name.GroupBy(Function(value) value).OrderBy(Function(t) t).Distinct().ToList()


  For Each date_name In date_1 
      chart_date.Series(0).Points.AddXY(date_name(0), date_name.Count)
  Next



it has error like this:

An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

Additional information: At least one object must implement IComparable.
Posted
Updated 3-Aug-15 16:08pm
v2
Comments
Sergey Alexandrovich Kryukov 3-Aug-15 22:03pm    
Well, implement IComparable. What have you tried so far?
—SA

Please see my comment to the question.

Here is a hint for you. Have a enumeration type defining months in exact spelling, such as enum Months = { Sunday, Monday, ...}. Parse each item into month and day, and recognize the enumeration value from month string using System.Enum.Parse. Then parse date. Implement the relationship of order for some type representing combination of month and day.

Alternatively, use System.DateTime.ParseExact or System.DateTime.TryParseExact and represent each line as the instance of System.DateTime.

—SA
 
Share this answer
 
v2
My suggestion would be to convert them into datetime and then sort as necessary.

OrderBy in this case will sort on string.
If the property was datetime you would have got the right results.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900