Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sort a list of elements based on string value in element

I have a list of arrays that have a value called status. I want to sort these by placing the arrays with the "Active" status to the front of the list. This is to display the active elements first in a later function. Any good ideas how to sort and place the active "contracts" first?

IEnumerable<Contract> mappedContracts = MapContractsToContracts(contracts);
mappedContracts.OrderBy(x => x.Status == "Active");
return mappedContracts.ToList();

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Presuming Status is a string and not other statuses are alphabetically before "Active".

IEnumerable<Contract> mappedContracts = MapContractsToContracts(contracts);
return mappedContracts
    .OrderBy(x => x.Status)
    .ToList();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading