这是C#入门经典里面的例子,就是编译不过,请高手帮忙
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace ConsoleApplication1
{
     class Program
     {
         static int Maxima(int[] integers, out int[] indices) //参数一记录最大数,参数二记                                                                  录数组序号
         {
             Debug.WriteLine("搜索最大数开始.");  //在output窗口输出调试信息
             int maxVal = integers[0];     //定义maxVal变量存储最大值,初定为数组第一个整数
             indices = new int[1];             //定义indices数组存储最大值的序号
             indices[0] = 0;                       //初定最大值的序号为0,即第一个数为最大值
             int count = 1;                     //最大值的个数
             Debug.WriteLine(string.Format("初始化最大值为{0},位置为0.", maxVal));
             //在output输出初始化信息
             for (int i = 1; i < integers.Length; i++)  //函数的主体为一个循环
             {
                 Debug.WriteLine(string.Format("现在开始搜索最大值,从序号{0}开始。", i));
                 if (integers[i] > maxVal)
                 {
                     maxVal = integers[i];  //分别对第一初始值进行比较
                     count = 1;           //发现更大的值时,count计数不变
                     indices = new int[1];  //每发现一个最大值就重新定义一个数组来存储序号
                     indices[0] = i;       //更新最大数的序号
                     Debug.WriteLine(string.Format(
                         "发现新的最大值为{0},序号为{1}", maxVal, i));
                 }
                 else
                 {
                     if (integers[i] == maxVal)       //相同的值
                     {
                         count++;                   //最大值个数增加1
                         int[] oldIndices =indices;   //旧最大值的序号备份到oldIndices中=====说indices没定义===
                         int[] indices = new int[count]; //新定义数组,新的长度
                         oldIndices.CopyTo(indices, 0); //复制就序号到新数组中,从0开始复制
                         indices[count - 1] = i;    //新的最大值的序号
                         Debug.WriteLine(string.Format("发现相同的最大值在第{0}序号", i));
                     }
                 }
             }
             Trace.WriteLine(string.Format("最大值为{0},一共有{1}个", maxVal, count));
             Debug.WriteLine("搜索最大值完毕");
             return maxVal;
         }
         static void Main(string[] args)
         {
             int[] testArray = { 4, 7, 4, 7, 5, 6, 8, 9, 5, 9, 7, 8, 9 }; //要测试的数组
             int[] maxValIndices; // 存储最大值序号的数组
             int maxVal = Maxima(testArray, out maxValIndices);
             Console.WriteLine("最大数为{0},分别在:", maxVal);
             foreach (int index in maxValIndices)
             {
                 Console.WriteLine(index);
             }
             Console.ReadKey();
         }          
     }
}
------解决方案--------------------
int[] oldIndices =indices; //旧最大值的序号备份到oldIndices中=====说indices没定义===
int[] indices = new int[count]; //新定义数组,新的长度
问题在int[]indices,因为你重名了,定义了一个跟参数一样的局部变量,改成
int[] indices1 = new int[count]; //新定义数组,新的长度
这样就可以了
------------------------------------
话说这个例子我照着书上调试过的,没问题的啊,你输入错误了吧