In the compareto method, you pull out whatever you want to pull out, make the 
determination, and return a negative value to indicate less than, a zero to 
indicate equality, and a positive value to indicate greater than.  All that the 
sort methods are doing is comparing the objects in the list to each other 
(using the CompareTo methods of each object to see how to do the sort).  The 
sort methods do not know or care what logic you use to determine greater than, 
equal or less than.  The interface defines the single parameter of the 
CompareTo method as Object.  Typically, the logic in the CompareTo method in a 
given class has to test the parameter object to make sure that it is of the 
same type.  If it is, the logic casts the incoming object to the appropriate 
type.  At that point, you can pull out whatever properties that are of interest 
in making the comparison.  If you want to sort on three items, A, B, and C, in 
that order, the logic would look something like this:
 
if this.A > other.A
  return greater // the relative values of B and C are not relevant
elseif this.A < other.A
  return lesser // the relative values of B and C are not relevant
elseif this.B > other.B
  return greater // the relative values of C are not relevant
elseif this.B < other.B
  return lesser // the relative values of C are not relevant
elseif this.C > other.C // at this point both A and B are equal, C is the tie 
breaker
  return greater
elseif this.C < other.C
  return lesser
else
  return equal
endif
 
Please check the documentation for the exact details.  I am doing this from 
memory and that is always risky. 
 
Jon Stonecash



> Date: Fri, 15 Sep 2006 15:19:41 -0400> From: [EMAIL PROTECTED]> Subject: Re: 
> [ADVANCED-DOTNET] ArrayList Sort Method> To: 
> [email protected]> > I'm following you there but how do I 
> pull out two properties and sort the> list based on those two properties.  
> That is what I'm not following.> > Shawn Hevel, API, AIT> Lead Programmer 
> Analyst> Information Technology Department> South Carolina Farm Bureau 
> Insurance Companies> Phone: (803) 936-4331> Fax: (803) 936-4629> Work Email: 
> [EMAIL PROTECTED]> Home Email: [EMAIL PROTECTED]> > > -----Original 
> Message-----> From: Jon Stonecash [mailto:[EMAIL PROTECTED] > Sent: Friday, 
> September 15, 2006 2:16 PM> To: [email protected]> Subject: 
> Re: [ADVANCED-DOTNET] ArrayList Sort Method> > Could you not implement the 
> IComparable interface in the DocumentReference> class.  This requires you to 
> implement a single method, CompareTo that> determines if another object is 
> "bigger than" , "equal to" or "less than"> the implementing object.  The Sort 
> methods of Array and ArrayList use this> method to decide what the order of 
> items in the array are.  How you> determine the relative position is strictly 
> up to you.  You can use one> property or a dozen; it is strictly your call.  
> You could even use a random> number if that were your fancy.Jon Stonecash> > 
> > Date: Fri, 15 Sep 2006 14:06:54 -0400> From: [EMAIL PROTECTED]>> Subject: 
> [ADVANCED-DOTNET] ArrayList Sort Method> To:> 
> [email protected]> > I have an unusual situation or at> 
> least I think I do.  I need to sort an> ArrayList, but my ArrayList is made> 
> up of a class called DocumentReference.> Inside this class are different> 
> properties that pertain to a Document> (ReportId, VersionId, Description> 
> etc).  What I need to do is sort this> based on certain criteria.  They only> 
> way I know how to do this is by> building a temporary table with columns> 
> that pertain to each property.  I> would then move the value of each> 
> property into the specified column until> all properties are read.  Once all> 
> ArrayList members are read I can create a> DataView  from the DataSet and do> 
> the following:> > > > dvTopicList.Sort = "VersionID DESC" or> 
> dvTopicList.Sort = "Description,> ReportID"> > > > After the list is sorted,> 
> I would rebuild my ArrayList and return this back> to the calling program.>> 
> > > > I know that ArrayList has a sort method but I don't think it will work> 
> for> me.> > > > Does anyone have any ideas about approaching this? or a> 
> better way of doing> it?> > > > Thanks,> > > > Shawn Hevel, API, AIT> Lead> 
> Programmer Analyst> Information Technology Department> South Carolina Farm> 
> Bureau Insurance Companies> Phone: (803) 936-4331> Fax: (803) 936-4629> Work> 
> Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> Home Email:> [EMAIL 
> PROTECTED]> > > > > ===================================> This list> is hosted 
> by DevelopMentor®  http://www.develop.com> > View archives and> manage your 
> subscription(s) at http://discuss.develop.com> 
> ===================================> This list is hosted by DevelopMentor®  
> http://www.develop.com> > View archives and manage your subscription(s) at 
> http://discuss.develop.com> > ===================================> This list 
> is hosted by DevelopMentor®  http://www.develop.com> > View archives and 
> manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to