override sort method

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone look at the code below and tell me why if I try compiling this it
tells me there is no sort method to override? I did not paste the actual
comparer classes. It acts as if it does not see the sort method of the
ArrayList class.

Thanks in advance
Marty U.

using System;
using System.Collections;
namespace MyCustomNamespace
{
/// <summary>
/// This class inherits arraylist and stores a collection of
/// Office Sub Groups.
/// </summary>
public class OfficeSubGroupCollection : ArrayList
{
public enum SubGroupFields {
GroupID,
GroupDescription,
GroupCode
}

public override void Sort(SubGroupFields sortField, bool IsAscending) {
switch (sortField) {
case SubGroupFields.GroupDescription:
base.Sort(new DescriptionComparer());
break;
case SubGroupFields.GroupCode:
base.Sort(new CodeComparer());
break;
} //End Switch
} //End Sort Method
 
Because your Sort method has a different signature than Sort methods in
ArrayList.
ArrayList has only sort method for:
- public virtual void Sort();
- public virtual void Sort(IComparer);
- public virtual void Sort(int, int, IComparer);

There is not a ArrayList.Sort(SubGroupFields, bool) !
Override keyword is just when you override a method with the same signature
(same number of parameter and same type for parameter).

Lionel.
 
Back
Top