Use LINQ to move item to top of list

前端 未结 11 1407
轻奢々
轻奢々 2020-12-02 12:00

Is there a way to move an item of say id=10 as the first item in a list using LINQ?

Item A - id =5
Item B - id = 10
Item C - id =12
Item D - id =1

In th

11条回答
  •  情话喂你
    2020-12-02 12:38

    Its interesting the number of approaches you find when trying to solve a problem.

    var service = AutogateProcessorService.GetInstance();
    var allConfigs = service.GetAll();
    allConfigs = allConfigs.OrderBy(c => c.ThreadDescription).ToList();
    var systemQueue = allConfigs.First(c => c.AcquirerId == 0);
    allConfigs.Remove(systemQueue);
    allConfigs.Insert(0, systemQueue);
    

提交回复
热议问题