I have a list "Sites" with one of the items as "From" and "To". It is defined as string and is in the format "MM/yyyy". When I try to sort the list based on the year, I'm facing a small problem.
Data for "From" and "To" is
01/2012
04/2012
01/2013
06/2012
When I sort the list by using orderby, the output I'm getting is
01/2012
01/2013
04/2012
06/2012
which is incorrect.
List<Site> List = new List<Site>();
DataSet DS = ClientDB.Sites(Id);
if (DS.HasTable0AndRows())
{
IEnumerable<DataRow> _DataRow = DS.Tables[0].AsEnumerable();
List = _DataRow.Select(x => new Site()
{
FileNum = x["File_Num"].ToString(),
From = x["From"].ToString(),
To = x["To"].ToString(),
}).ToList();
}
return List.OrderBy(x => x.FileNum).ToList();
}
I understand that I have to use DateTime.Parse
inorder to convert the From and To but how do I use the DateTime.Parse
in the above case when i return the list?