本帖最后由 zhl406893081 于 2014-3-13 19:05 编辑
函数返回值是数组时如何返回?
我想返回一个数组,但只返回了数组的第一个值,C#里也没有指针,怎么返回一个数组?
- static void Main(string[] args)
- {
- int[] sum = new int[7];
- int max = 0, min = 0;
- int[] number = { 30, 43, 5635, 63, 142, 325, 6734 };
- sum[0] = MUS(ref number, out min, out max);
- Console.WriteLine("最小为{0} 最大为{1}", min, max);
- for (int i = 0; i < sum.Length; i++)
- {
- Console.WriteLine(sum[i]);
- }
- Console.ReadKey();
- }
- static int MUS(ref int[] number, out int min, out int max)
- {
- min = number[0];
- max = number[0];
- int[] aaa = new int[7];
- for (int i = 0; i < number.Length; i++)
- {
- aaa[i] = number[i];
- if (number[i] > max)
- max = number[i];
- if (number[i] < min)
- min = number[i];
- }
- return aaa[0];
-
- }
复制代码
|