Q:

InvalidOperationException with arrayLists

I am getting this exception:
Collection was modified; enumeration operation may not execute.
Directly after this code:
     else if (count == 0)
                    {
                        partCategory.Add(words[count].ToString());
                        foreach (string categoryS in partCategory)
                        {
                            if (categoryS != words[count].ToString())
                            {
                                partCategory.Add(words[count].ToString());
                            }
                        }
                    }

I am taking a guess that it may be the Add method that was used prior to it, but I'm not sure.
Call Stack Code:
**********.exe!**********m.FileController.readSortText(string fileName = "**********extracted\\PC120701.txt", System.Windows.Forms.ProgressBar newProgress = {Value = 0 Min = 0 Max = 100}) Line 78 + 0x207 bytes   C#

**********.exe!**********.mainForm.unzipFile(string fileName = "**********") Line 133 + 0x42 bytes  C#
**********.exe!**********.mainForm.decompress_Click(object sender = {Text = "Unzip"}, System.EventArgs e = {X = 49 Y = 7 Button = Left}) Line 163 + 0x17 bytes  C#

[External Code] 
**********.exe!**********.Program.Main() Line 18 + 0x28 bytes   C#

[External Code] 

Thanks for your future help!

A:

Yes that's because you are modifying the collection you are enumerating. 

