c#自定义排序方法

来源:互联网 发布:实施工程师sql笔试题 编辑:程序博客网 时间:2024/06/10 21:49

代码:

class Word    {        public string value { get; set; }        public int count { get; set; }    }    class WordCountCompare<T>:IComparer<Word>    {        public int Compare(Word x,Word y)        {            if (x.count > y.count) return -1;            if (x.count == y.count)            {                return string.Compare(x.value, y.value);            }            return 1;        }    }       wordList.Sort(new WordCountCompare<Word>()); //调用
0 0