I have a list of news unsorted items, some of which have a priority flag. I need the priority items to float to the top of the list, and then sort the rest by a date.
So, the end result is a list of news items that has the priority items showing at the top and the remainder sorted by date.
There has to be a better way to do it than this but I'm not sure what the best way would be -
foreach (var newsItem in newsItems)
{
if (newsItem.isPriority)
{
addToPriorityList(newsItem);
}
else
{
addToOtherList(newsItem);
}
}
foreach (var priorityItem in priorityList)
{
addtoMainList(priorityItem);
}
OtherList.SortbyDate();
foreach (var otherItem in otherList)
{
addtoMainList(otherItem);
}
Is there a more elegant way to pull this off? I assume I could use LINQ but I'm very new to it so I'm not comfortable with the syntax.