forum

Home / DeveloperSection / Forums / How to sort object in list and update object using linq?

How to sort object in list and update object using linq?

Anonymous User207003-Nov-2014
I am writing a function to sort a List using a property inside the list. I need to sort the MyClass object obj using the property Age of the list AnimalList and assign the sorted list back to obj. After performing the function obj should get updated with the new sorted object. My list value has got the sorted list now. I need to update that to obj.

I have tried many possibilities but couldn't bind it the list to the object.

publicvoid SortBlocks(MyClass obj)
{
      List<Animal> value = obj.AnimalList;
      value = value.OrderBy(val => val.Age).ToList();
}
 
publicinterfaceMyClass
{
     List<Animal> AnimalList { get; set; }
}
publicclassAnimal
{
     publicstring color { get; set; }
     publicuint Age { get; set; }
}


Updated on 04-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By