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

在一个方法中利用out返回2个数组
 static void GetRandomNumber(out List<int> intArray, out int[] counts)
        {
            //List<int> intArray = new List<int>();
            //int[] counts = new int[5];
            Random ran = new Random();
            int i = 0;
            while (i <= 100)
            {
                //产生随机数
                int num = ran.Next(1, 7);
                intArray.Add(num);
                //统计出现次数
                counts[num - 1]++;
                i++;
            }

        }



错误 3 控制离开当前方法之前必须对 out 参数“intArray”赋值 E:\Visual c#2008核心编程\exam\test10\Program.cs 27 21 test10

错误 1 使用了未赋值的 out 参数“intArray” E:\Visual c#2008核心编程\exam\test10\Program.cs 37 17 test10

------解决方案--------------------
你的Log已经说的很清楚了。
错误3,在方法结束之前保证intArray and counts都初始化了,这是使用out的要求。
错误1,使用intArray之前先初始化,intArray=new List<int>();