本帖最后由 一片白 于 2014-5-4 16:07 编辑
static void Main(string[] args) { //建立泛型集合 键值对,记录每个字符出现的次数 Dictionary<int, int> dictionary = new Dictionary<int, int>();
Random random = new Random(); int[] intArr = new int[100]; for (int i = 0; i < 100; i++) { //random = new Random(); 注释掉这儿,:P int iRandom = random.Next(1, 7); if (!dictionary.ContainsKey(iRandom))//如果不包含该键,则加入集合中 { dictionary.Add(iRandom, 1); } else { dictionary[iRandom]++; } }
foreach (KeyValuePair<int, int> kvp in dictionary) { Console.Write("“{0} {1}”", kvp.Key, kvp.Value); } Console.ReadKey(); } 结果是:
static void Main(string[] args) { //建立泛型集合 键值对,记录每个字符出现的次数 Dictionary<int, int> dictionary = new Dictionary<int, int>();
Random random = new Random(); int[] intArr = new int[100]; for (int i = 0; i < 100; i++) { random = new Random(); //不注释掉这儿了!:P{:3_65:} int iRandom = random.Next(1, 7); if (!dictionary.ContainsKey(iRandom))//如果不包含该键,则加入集合中 { dictionary.Add(iRandom, 1); } else { dictionary[iRandom]++; } }
foreach (KeyValuePair<int, int> kvp in dictionary) { Console.Write("“{0} {1}”", kvp.Key, kvp.Value); } Console.ReadKey(); } 结果是:
|