Results 1 to 4 of 4

Thread: IComparable

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    IComparable

    I've implemented this before a very long time ago and since I forgot, i read up about it again to see what the method should look like for CompareTo()

    I have implemented this correctly but when I sort the ArrayList giving it null as a parameter, it seems not to sort it but do it in decending order.

    So:
    I have an arraylist of specific objects (note, this is not a general list....this is using .NET 1.1)

    I have implemented the IComparable interface and its method for the object type in question.

    I did an: collection.Sort(null); and it didnt seem to sort it (but it does call the compareTo() method):

    Code:
    #region IComparable Members
    
    		public int CompareTo(object obj)
    		{
    			// TODO:  Add VacancyInfoHelper.CompareTo implementation
    			if ((obj is VacancyInfoHelper) == false)
    			{
    				return -1;
    			}
    
    			VacancyInfoHelper helper = (VacancyInfoHelper)obj;
    			return this.rank.CompareTo(helper.rank);
    		}
    
    #endregion

    edit: forgot to mention it is an ASP.NET application and since the private field "rank" is set to 0 by default, would that make much difference? I believe it is so how do I do sorting on an ASP.NET based application?
    Last edited by Techno; Jul 4th, 2007 at 06:58 AM.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width