I have a list of Employee objects .Employee Class can be as below:
Class Emplyoyee
{
public string name;
public string DateOFJoining; //Please note here date is in string format
}
Now i want to display the list of employee with latest employee on top so am using below code for it :
List<Employee> lst = GetEmployes();
lst = lst.OrderByDescending(x => x.DateOFJoining).ToList();
//Here binding to the repeater
rptEmp.DataSource = lst.Take(2);
rptEmp.DataBind();
Problem: Here its ordering treating date as string .But i want to order by date.Can anyone help me on this?
Thanks in advance.
You would need to convert
x.DateOfJoininginto aDateTimein theOrderByDescendingexpression. If you’re confident in the quality of your dates, you could try: