Sorting an IList in C#

前端 未结 15 2348
臣服心动
臣服心动 2020-11-28 06:36

So I came across an interesting problem today. We have a WCF web service that returns an IList. Not really a big deal until I wanted to sort it.

Turns out the IList

15条回答
  •  借酒劲吻你
    2020-11-28 07:00

    This looks MUCH MORE SIMPLE if you ask me. This works PERFECTLY for me.

    You could use Cast() to change it to IList then use OrderBy():

        var ordered = theIList.Cast().OrderBy(e => e);
    

    WHERE T is the type eg. Model.Employee or Plugin.ContactService.Shared.Contact

    Then you can use a for loop and its DONE.

      ObservableCollection ContactItems= new ObservableCollection();
    
        foreach (var item in ordered)
        {
           ContactItems.Add(item);
        }
    

提交回复
热议问题