Sunday, May 15, 2011

Sort a class Employee

Here is a simple example for sorting an Employee class

public class MainClassToSortEmployee
{
public enum SortDirection { Ascending, Decending }

public static List Sort1(ref List list,
Func sorter, SortDirection direction)
{
if (direction == SortDirection.Ascending)
return list = list.OrderBy(sorter).ToList();
else
return list = list.OrderByDescending(sorter).ToList();
}

static void Main()
{

}
}

public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime dateTime { get; set; }

public Employee(string p, string p_2, DateTime dateTime)
{
this.FirstName = p;
this.LastName = p_2;
this.dateTime = dateTime;
}
}

next task is to convert it to a Generic Linq

No comments:

Post a Comment