我有一個小問題,下面的代碼(C#),它循環以爲陣列,它然後檢查USER_ID有user_post大於50,它然後寫USER_ID,預期的結果是循環雖然數組然後如果然後輸出結果?
12
13
但實際輸出是
12
12
12
最新的代碼是什麼問題?我嘗試了一個標準的循環,但不能正確嗎?
int[] user_id = new int[64];
int[] group_id = new int[64];
int[] user_post = new int[64];
//user 55
user_id[0] = 10;
group_id[0] = 8;
user_post[0] = 4;
//user56
user_id[1] = 11;
group_id[1] = 2;
user_post[1] = 15;
//user57
user_id[2] = 12;
group_id[2] = 2;
user_post[2] = 55;
//user58
user_id[3] = 13;
group_id[3] = 2;
user_post[3] = 56;
foreach (int i in group_id)
{
if (group_id[i] == 2)
if (user_post[i] > 50)
Console.WriteLine(Convert.ToString(user_id[i]));
}
Console.WriteLine("Press any key too continue...");
Console.ReadLine();
// continue...
Hmmmm,這不是一個不好的問題,但我認爲通過學習使用IDE中的調試功能,您可以獲得比從SO更快的答案。 – Juliet 2011-02-06 21:51:07
+1完全同意..人們正在採取SO作爲替代調試器 – 2011-02-06 21:55:31