Reputation: 467
I have a list as below:
IList<Employee> emp = new List<Employee>
{
new Employee() {Id=1, Name = "A", Age = 20, Address = "X"},
new Employee() {Id=2, Name = "B", Age = 21, Address = "Y"},
new Employee() {Id=3, Name = "C", Age = 22, Address = "Z"},
};
and another list:IList<Object> emp2=new List<Object>();
If I want to assign emp to emp2 like:emp2=emp;
how can I do this?
Upvotes: 0
Views: 1086
Reputation: 43056
I would do this:
List<Employee> emp = //insert initialization code here
IList<object> emp2 = emp.OrderBy(e => e.WhicheverPropertyYouWantToSortBy).Cast<object>().ToList();
Upvotes: 1
Reputation: 4828
You can try this:
foreach (var employee in emp)
{
emp2.Add(employee);
}
Upvotes: 1