-7
我得到兩個錯誤「無法分配給'C',因爲它是'foreach迭代變量'和'語法錯誤,值預期'我真的不知道我的錯誤在哪裏?我可以用一些新鮮的眼睛來證明我的不足。我找不到我的錯誤
int[] numDictionary = new int[] { 5, 5, 5, 7, 7, 7, 9, 7, 9, 9, 9, 1 };
IDictionary<int, int> count = new SortedDictionary<int, int>();
//count = new SortedDictionary<int, int>();
//int SortedDictionary = count;
foreach (var c in numDictionary)
{
if (c > 0)
{
count[c] = count.[c] + 1;
}
}
//return count.ToString();
Console.WriteLine(count);
Console.ReadKey();
'count'是一本字典。 'c'是一個int。無法將'count'分配給'c'。另外,正如錯誤所述,它是一個循環變量。你不能改變它:這是循環的工作。 –
而你正在創造'count'兩次。 'count [c] = c [] + 1'應該做什麼?也許你應該閱讀一些教程。瞭解類型,數組等。 –
從您的說明或您發佈的代碼中,您不太清楚您希望做什麼。 – Drefetr