returning array sortedDictionary

Posted on 2006-05-07
Last Modified: 2010-05-18
See the code below, I want to get rid of the ArrayList, as its not neccessary I suppose.

// create a new sorted dictionary
          SortedDictionary<string, string[]> thesaurus =
            new SortedDictionary<string, string[]>();

public string[] WordList()
            //no need to sort, because we are utilizing sortedDictionary.
            ArrayList sortedList = new ArrayList(1);
            foreach (KeyValuePair<string, string[]> kvp in thesaurus)
            return (string[])sortedList.ToArray(typeof(string));                                      

this is much nicer than above code but I cant get it to work

public string[] WordList()
            return (string[])thesaurus.Keys;                                      

Thanks for the help in advance
Question by:Thunder_scream
    LVL 11

    Accepted Solution

    Thunder_scream, this should do:

      public string[] WordList()
        string[] wordList = new string[thesaurus.Keys.Count];
        thesaurus.Keys.CopyTo(wordList, 0);
        return wordList;
    LVL 2

    Author Comment

    cheers is works like a charm

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now