Quote:
int count = 0;
if (result.ContainsKey(file[i].Extension))
{
count++;
}
else
{
count = 1;
}
That code does nothing useful. You declare a local variable and initialize it to
0
. If the dictionary contains the extension of the current file, you increment it to
1
; otherwise, you set it to
1
. You then throw it away.
You also never add anything to the dictionary, so it will always be empty.
What you need to do is read the current count from the dictionary, if it exists; increment it; and then put it back into the dictionary.
if (result.ContainsKey(file[i].Extension))
{
result[file[i].Extension] = result[file[i].Extension] + 1;
}
else
{
result[file[i].Extension] = 1;
}
NB: There are more efficient ways to do this with a dictionary; but as this is your homework assignment, I'll assume that either you'll cover them in a later lesson, or you'll research them yourself.