I'm brand new to C# and the concept of hash tables/dictionary's and have been searching for a straight answer on this for quite awhile, but I can not find any solutions that actually works (likely due to my ignorance of the subject) so I need a solution in simple terms if possible.
Also, if it makes a difference, the String
s and int
s in the dictionary are not data members or even parameters.
More Description:
The program overall, is to import words via text file or direct user input then save them and the number of times they appear (AKA store in Dictionary/Sorteddictionary
) then allow users to reorganize the data, alphabetically, reverse alphabetically, or by frequency and/OR print them to the console or write the data to a new .txt file.
However right now I am only trying to get the sorting of the dictionary to work.
Example input: Another great story and another great adventure.
Example Output(alphabetically): Words Starting with letter A: another adventure and Letter Starting with letter G: great (Ect.)
Example Output(reverse alphabetically): Words Starting with letter S: story Words Starting with letter G: great (ect.)
Output(frequency): number of words occurring 2 time(s): another great number of words occurring 1 time(s): and adventure story.
Hope this helps. I'm not sure it's the best way to approach your problem, but it should help you to familiarise yourself with some of the options / see why some of the guys on here are advising against it. If you let us know more about what you're trying to do we can better advise alternate approaches.
Good luck / hope you're enjoying c# so far.
EDIT
Based on the new info in your question here's my attempt at a neater solution:
EDIT
Here's the same code with the functionality in a class and the output kept in the program: using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions;