-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: DIGITAL PIRATE
Message 2 in Discussion

Hi,   You if you want to sort an arraylist that contains custom classes, then u need 
to implement IComparable interface and implement it. It has just one method int 
CompareTo(object) and you need to implement it by writing code that will compare the 
object passed thru arugment and current instance and return appropriate value. The 
return value is 0, less than zero, or greater tha zero. I hope u got this ..    public 
class MyClass : IComparable { 
   public int MyField; 
   public MyClass(int value){ 
      MyField = value; 
  } 
  public int CompareTo(object) { 
      MyClass passedIn = (MyClass) object; 
      if(this.MyField != passedIn.MyField) { 
        if(this.MyField > passedIn.MyField) { 
            return 1; // this instance is greater than passed in one 
        } 
        return -1;  // this instance is less than passed in one 
      } 
      return 0; // this instance is equal to passed in one 
  } 
} 

ArrayList al = new ArrayList(); 
al.Add(new MyClass(0)); 
al.Add(new MyClass(3)); 
al.Add(new MyClass(2)); 
al.Sort()    HTH -Shamir

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to