ArrayList.Sort method in C#
2004-08-16 19:40
204 查看
Today I first used the sort method of ArrayList in C#.
In order to sort the data under my business logic I designed a class inherit the IComparer interface,
then I realized the method -- Compare of the interface,in which I coded some logic to
compare two objects and return a value indication whether one is less than,equal to
or greater than the other.
There is a simple sample here
ArrayList myAL = new ArrayList();
myAL.Add("The");
myAL.Add("QUICK");
myAL.Add("BROWN");
IComparer myComparer = new myCompare();
myAL.Sort(0, 3, myComparer);
public class myCompare : IComparer
int IComparer.Compare(Object x, Object y)
return ((new CaseInsensitiveComparer()).Compare(y, x));
}
}
I think the sort way of ArrayList designed in C# is great , we can sort the elements in any way we want
In order to sort the data under my business logic I designed a class inherit the IComparer interface,
then I realized the method -- Compare of the interface,in which I coded some logic to
compare two objects and return a value indication whether one is less than,equal to
or greater than the other.
There is a simple sample here
ArrayList myAL = new ArrayList();
myAL.Add("The");
myAL.Add("QUICK");
myAL.Add("BROWN");
IComparer myComparer = new myCompare();
myAL.Sort(0, 3, myComparer);
public class myCompare : IComparer
int IComparer.Compare(Object x, Object y)
return ((new CaseInsensitiveComparer()).Compare(y, x));
}
}
I think the sort way of ArrayList designed in C# is great , we can sort the elements in any way we want
相关文章推荐
- ArrayList.Sort method in C#
- Part 67 to 70 Talking about method parameters in C#
- How to call c++ exported method and classes in c#
- c# ArrayList 的 Sort()方法的使用
- C# 对 结构体 或 类对象 的arraylist 排序 sort()
- C#函数编译出错:Inconsistent accessibility: parameter type ‘aaa.bbb.ccc’ is less accessible than method ‘aa
- 在C#中直接使用Open API的方法 / A Method of Using Open API in C#
- (.NET) IntelliSense difference of Extension Method name in Statement Completion for VB and C#.
- Mocking a method to throw an exception in C#
- How to call code behind method in JavaScript in C# and VS2010?
- 转:c# ArrayList 的 Sort()方法的使用
- c# 学习笔记 ArrayList的Sort方法的实现
- 【转】How to call c++ exported method and classes in c#
- My FactoryMethod in C#
- C# 数组集合 <一>基本概念(Array&ArrayList&List<T>&SortList&LinkList的实现Code)
- Dynamic in C# VII: Phantom Method Semantics
- c#:sort在非泛型类ArrayList,泛型类List<>中的用法
- Part 61 to 63 Talking about partial class and partial method in C#
- C#ArrayList-sort
- Breaking parallel loops in .NET C# using the Stop method z