Sorting a hashtable - strange error, please help!!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • almurph@altavista.com

    Sorting a hashtable - strange error, please help!!

    H ieveryone,

    Can you help me please? I am trying to sort a hashtable but get the
    error: "Cannot implicity convert type void to
    System.Collecti ons.ArrayList"

    I am doing the following:


    ****BEGIN CODE****


    public ArrayList SomeMethod()
    {
    Hashtable myHT = new HashTable();

    ArrayList keys = GetKeys (HT);

    return keys.sort();
    }


    //Return an arraylist of Hashtable keys
    public ArrayList GetKeys(Hashtab le table)
    {
    return (new ArrayList(table .Keys));
    }


    ****END CODE****


    However under the "keys.Sort( )" method call I get the error: "Cannot
    implicity convert type void to System.Collecti ons.ArrayList"

    I'm stuck. Would greatly appreciate any comments/suggestions/
    corrections that you may be able to offer.

    Thanking you,
    Al.
  • Marc Gravell

    #2
    Re: Sorting a hashtable - strange error, please help!!

    The Sort() method does not return anything - you need to break this up:

    keys.Sort();
    return keys;

    Note that you might want to consider List<Tif you are using .NET 2.0
    or above.

    Marc

    Comment

    • Ben Voigt [C++ MVP]

      #3
      Re: Sorting a hashtable - strange error, please help!!

      Marc Gravell wrote:
      The Sort() method does not return anything - you need to break this
      up:
      keys.Sort();
      return keys;
      >
      Note that you might want to consider List<Tif you are using .NET 2.0
      or above.
      List<Twould be used with Dictionary<T, TValuejust as ArrayList is used
      with Hashtable.

      Mixing and matching could get quite ugly very fast.
      >
      Marc

      Comment

      Working...