- 最後登錄
- 2024-4-23
- 在線時間
- 0 小時
- 註冊時間
- 2016-8-22
- 閱讀權限
- 20
- 精華
- 0
- UID
- 16624936
- 帖子
- 61
- 積分
- 49 點
- 潛水值
- 26790 米
| 如果你忘記伊莉的密碼,請在登入時按右邊出現的 '找回密碼'。輸入相關資料後送出,系統就會把密碼寄到你的E-Mail。 - Random r = new Random();
- Dictionary<int, int> dic = new Dictionary<int, int>();//(.Net Framework2.0以上版本)
- for (int i = 0; i < 30; i++)
- {
- int n = r.Next(1, 101);
- if (dic.ContainsKey(n))
- dic[n] = int.Parse(dic[n].ToString()) + 1;//已存在數量加1
- else
- dic.Add(n, 1);//不存在添加項目
- }
- foreach (System.Collections.Generic.KeyValuePair<int, int> d in dic)
- Console.WriteLine("{0}:{1}", d.Key, d.Value);
- //也可以用ConcurrentDictionary<TKey, TValue>(.Net Framework4.0以上版本)
- System.Collections.Concurrent.ConcurrentDictionary<int, int> cds = new ConcurrentDictionary<int, int>();
- for (int i = 0; i < 30; i++)
- {
- int n = r.Next(1, 101);
- if (cds.ContainsKey(n))
- cds[n] = int.Parse(cds[n].ToString()) + 1;
- else
- cds.TryAdd(n, 1);
- }
- foreach (System.Collections.Generic.KeyValuePair<int, int> d in cds)
- Console.WriteLine("{0}:{1}", d.Key, d.Value);
複製代碼 ... |
|