c#多重排序

Ern*_*ngs 0 c# sorting

我有一个PlanSolution 1,2,3的3个级别,我需要先按.levelId排序,然后按字母顺序对属于该级别的解决方案进行排序.

PlanSolution[] planSolutions = wsAccess.GetPlanSolutionsForPlanRisk(planRisk.Id);
                    List<PlanRisk> planSolutionsList = new List<PlanRisk>(planSolutions);


                    planSolutionsList.Sort(delegate(PlanSolution x, PlanSolution y)
                    {
                        //HELP lol
                    });
Run Code Online (Sandbox Code Playgroud)

Jim*_*mmy 6

LINQ救援!

planSolutionsList = planSolutions
    .OrderBy(x => x.id)
    .ThenBy(x => x.Name)
    .ToList(); // is this necessary?
Run Code Online (Sandbox Code Playgroud)

对于原始格式 - 您只希望比较器将ID优先于名称

planSolutionsList.Sort( (x, y) => 
{
   //HELP lol
   if (x.id != y.id) return x.id - y.id;
   else return x.Name.CompareTo(y.Name);
});
Run Code Online (Sandbox Code Playgroud)