日期:2014-05-17  浏览次数:20778 次

一个Dictionary集合的疑问。麻烦帮忙下,谢谢!
            char[] chArray = new char[] {'零','一','二','三','四','五'};
            Dictionary<char, char> dic = new Dictionary<char, char>();
            for (int i = 0; i <chArray.Length; i++)
            {
                dic.Add(Convert.ToChar(i),chArray[i]);
            }
            Console.WriteLine("请输入数字0-5");
            char num = Convert.ToChar(Console.ReadLine().Trim());
            Console.WriteLine(dic[num]);
            Console.ReadLine();












为什么不可这样做呢?可以解释下吗?谢谢!
dictionary

------解决方案--------------------
                dic.Add(Convert.ToChar(i+48), chArray[i]);

------解决方案--------------------

        //
        // 摘要:
        //     将指定字符串的第一个字符转换为 Unicode 字符。
        //
        // 参数:
        //   value:
        //     长度为 1 的字符串。
        //
        // 返回结果:
        //     与 value 中第一个且仅有的字符等效的 Unicode 字符。
        //
        // 异常:
        //   System.ArgumentNullException:
        //     value 为 null。
        //
        //   System.FormatException:
        //     value 的长度不是 1。
        public static char ToChar(string value);

  //
        // 摘要:
        //     将指定的 32 位有符号整数的值转换为它的等效 Unicode 字符。
        //
        // 参数: