I've posted a question before , here: C# Array of List Index out of bounds Its about the same code. My code is working okay but when it finishes a file , instead of breaking out to the next filename (in a foreach loop) it remains in the same - that way matches always repeats and he just adds the same stuff in different list positions. I've tried changing the position of fs.Close() , adding a break statement but none of those worked.
What am i doing wrong in that case ? On my logical view it should go to the outer loop after it finishes the specific file.
I edited the code to the minimal need - anyway here's a link with the full code: http://pastebin.com/xcKczQLC
This link with the whole code contains the part where i open the file.
Thanks.
foreach (string fileName in fullFileName) //Start processing each file
{
// Lots of code here - reading a mixed file - no need to show
bool b = filecontents.Contains("CIP3EndOfFile");
if(b)
{
//Code manipulating contents in filecontents (a string)
var matches = Regex.Matches(query, pattern);
//When the foreach (Match m in matches) loop ends he always returns to the line above
finalcontent[listpos] = new List<xmldata>();//Initializing a list for each filename
foreach (Match m in matches)
{
//Lots of code doing some operations with the found match
if (i < colors_str.Length)
{
finalcontent[listpos].Add(new xmldata//The exception is thrown right here
{
colorname = colors_str[i],
colorvalues = values,
});//Closing list add declaration
}//Closing if
i++;
}//Closing foreach loop
if (i >= colors_str.Length)
{
listpos++;
i = 0;
}
fs.Close();//closing current file
//In this moment i expected that it would go for the foreach (string fileName in fullFileName) loop
//Instead he returns to this inner foreach loop
}//Closing boolean if
}//End file reading - closing for
}//Finished processing each filename (string filename in filename)