使用LINQ中的OrderByDescending和ThenBy来按顺序排序筛选和特定数据。以下是一个示例:
List data = new List()
{
"apple",
"banana",
"apple",
"grapefruit",
"orange",
"cherimoya"
};
var sortedData = data.OrderByDescending(d => d == "apple").ThenBy(d => d);
foreach (string d in sortedData)
{
Console.WriteLine(d);
}
这将首先按照“apple”在数据中作为特定数据进行排序,然后按照字母顺序对其余数据进行排序。输出将如下:
apple
apple
banana
cherimoya
grapefruit
orange
上一篇:按特定数据对字符串进行排序
下一篇:按特定数量将列表分组成范围