I have an arraylist and i'd like to sort them in 3 different ways. I know how to make it sort just ONE way by putting these codes in my class:
and I just call ArrayList.sort() and it does it fine. But I would like to sort my arraylist based on different properties in my class. I noticed there is a ListArray.sort(Icomparer) function call. I'm guessing that is the key to the solution to my problem. But how do I use it?Code:int IComparable.CompareTo(object obj) { FoneStruct objFone = (FoneStruct)obj; string str1 = this.name + this.number; string str2 = objFone.name + objFone.number; if(str1 == str2) return 0; else return str1.CompareTo(str2); }




Reply With Quote