zoukankan      html  css  js  c++  java
  • c#中ObservableCollection<T>排序方法

    之前用到的一段代码,记录一下

     1     public static class ObservableExtension
     2     {
     3         public static void Sort<TSource, TKey>(this Collection<TSource> source, Func<TSource, TKey> keySelector)
     4         {
     5             List<TSource> sortedList = source.OrderBy(keySelector).ToList();
     6             source.Clear();
     7             foreach (var sortedItem in sortedList)
     8                 source.Add(sortedItem);
     9         }
    10 
    11         public static void Sort<T>(this ObservableCollection<T> collection) where T : IComparable
    12         {
    13             List<T> sortedList = collection.OrderBy(x => x).ToList();
    14             for(int i = 0;i<sortedList.Count();i++)
    15             {
    16                 collection.Move(collection.IndexOf(sortedList[i]), i);
    17             }
    18         }
    19     }
  • 相关阅读:
    点子
    点子
    ruby crawler Anemone
    创业站
    我友网 没前途
    创意
    电商站
    尿布
    创意
    青番茄好项目
  • 原文地址:https://www.cnblogs.com/rarator/p/6088615.html
Copyright © 2011-2022 走看看