• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 804
  • Last Modified:

returning array sortedDictionary

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)
            {                
                sortedList.Add(kvp.Key);                
            }          
            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
0
Thunder_scream
Asked:
Thunder_scream
1 Solution
 
Expert1701Commented:
Thunder_scream, this should do:

  public string[] WordList()
  {
    string[] wordList = new string[thesaurus.Keys.Count];
    thesaurus.Keys.CopyTo(wordList, 0);
    return wordList;
  }
0
 
Thunder_screamAuthor Commented:
cheers is works like a charm
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now