Clear the word count of a C# Sorted Dictionary

I have an arraylist of sortedDictionaries.  Each dictionary represents the words in a text file.  After one text file is read, I load another one.  However, even though I clear the sortedDictionary the words are cleared, however, the count of that word is not cleared.  I am not sure what to do.   Below is the code that I run after each page is processed.  The words are correct, however, the counts are off, for example the word "example" appears twice on each page, but the count of the third dictionary shows the count as six.  The words, clear, but the count does not.  

Any help would be greatly appreciated.
pageWords = new SortedDictionary<string, int>();

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I take it that code is in a loop - if you are instantiating a new SortedDictionary every time around, why do you need to clear the new object?
shanemayAuthor Commented:
I am using a loop, I thought instantiating a new SortedDictionary every time would clear the count, but is does not.  So I tried using the Clear method, the clears the words, but not the counts.  The clear method is not needed, I just tried it.  

Thank you for the reply.  
Hello again, shanemay :-)

Why are you using the word as the key in each sortedlist item?
Also, here is some test code that worked for me - at the end of the loop, each SortedDictionary's count is 10.:

List<SortedDictionary<int, string>> x = new List<SortedDictionary<int, string>>();
            for (int i = 0; i < 10; i++)
                SortedDictionary<int, string> sd = new SortedDictionary<int, string>();
                for (int y = 0; y < 10; y++)
                { sd.Add(y, "this_is_a_word"); }

Open in new window

Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

shanemayAuthor Commented:
Thank you for the response.  I think my approach is incorrect.  I have a large text file with each paragraph representing a "page" that needs it own dictionary.  How would it be best to loop through each paragraph? Each paragraph is separated by blank lines.  

Again, thank you for the response.  
find an instance of more than 1 consecutive line terminator (Environment.NewLine).
string[] paragraphs = System.Text.RegularExpressions.Regex.Split(document_text, Environment.NewLine + Environment.NewLine);
foreach (string para in paragraphs)
  //paragraph level operation
  foreach (string word in para)
     //word level operation

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shanemayAuthor Commented:
Thank you for the response.  My approach was incorrect, I was only searching for words and was not spliting the document up by paragraph first.  Again, thank you I really appreciate your help.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.