Hi,
Are you looking for a code to Sort the List which is inside the class. if that is the case then you can use the below code
Sorting the Records
//Sort the inner list using Orderby Method
Employee[] employeeDetails = {
new Employee { Name="Barley", Salary=8000,EmpData=objEmp.OrderBy(x=>x.Pfamt).ToList() },
new Employee { Name="Boots", Salary=4987 , EmpData=objEmp2.OrderBy(x=>x.Pfamt).ToList() },
new Employee { Name="Whiskers", Salary=1090, EmpData=objEmp3.OrderBy(x=>x.Pfamt).ToList() }
};
Above code will sort the inner list available inside the class employee. You can also use the OrderByDescending method to order the list in descending order.
Complete code is given below
Class:
//Populate Dummy Data
List<Emppay> objEmp = new List<Emppay>
{
new Emppay { Pfamt = Convert.ToDecimal("354.34") },
new Emppay { Pfamt = Convert.ToDecimal("123.34") },
new Emppay { Pfamt = Convert.ToDecimal("789.34") }
};
List<Emppay> objEmp2 = new List<Emppay>
{
new Emppay { Pfamt = Convert.ToDecimal("987.87") },
new Emppay { Pfamt = Convert.ToDecimal("345.34") },
new Emppay { Pfamt = Convert.ToDecimal("789.34") }
};
List<Emppay> objEmp3 = new List<Emppay>
{
new Emppay { Pfamt = Convert.ToDecimal("123.34") },
new Emppay { Pfamt = Convert.ToDecimal("345.34") },
new Emppay { Pfamt = Convert.ToDecimal("789.34") }
};
//Sort the inner list using Orderby Method
Employee[] employeeDetails = {
new Employee { Name="Barley", Salary=8000,EmpData=objEmp.OrderBy(x=>x.Pfamt).ToList() },
new Employee { Name="Boots", Salary=4987 , EmpData=objEmp2.OrderBy(x=>x.Pfamt).ToList() },
new Employee { Name="Whiskers", Salary=1090, EmpData=objEmp3.OrderBy(x=>x.Pfamt).ToList() }
};
public class Employee
{
public string Name { get; set; }
public int Salary { get; set; }
public List<Emppay> EmpData;
}
public class Emppay
{
public decimal Pfamt;
}
You can find a working sample demo in below link
http://dotnetfiddle.net/gMMjcy Thanks,
A2H
My Blog
Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator