学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
发新话题
打印

代码有一处错误。请教

代码有一处错误。请教

如下是Visual C#入门经典里128页的一个例子。我运行了有一个错误是“}expected”我觉得我的括号没有少啊。请问是怎么了呢?谢谢。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Ch07Ex01
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建源数据组
            int[] testArray = { 4, 7, 4, 9, 7, 8, 3, 9, 1, 9 };
            int[] maxValIndices;
            int maxVal = MAXima(testArray, maxValIndices);

            Console.WriteLine("Maxinum value is {0} found at element indices;", maxVal);
            foreach (int index in maxValIndices)
            {
                Console.WriteLine(index);
            }
            

           static int Maxima(int[] integers,out int[] indices)
            {
                int maxVal=testArray[0];
                int count=1;
                int i;

                for (i=1;i<testArray.length;i++)
                {
                    if (testArray[i]>maxVal)
                    {
                        maxVal=testArray[i];
                        count=1;
                        indices=new int[1];
                        indices[0]=i;
                    }
   
                    
                    else if(testArray[i]==maxVal)
                    {
                        count++;
                        int[] temp=indices;
                        indices=new int[count];
                        temp.CopyTo(indices,0);
                        indices[count-1]=i;
                    
                    }
                           
                    return maxVal;
               
                }
            
            }
        }
     }

TOP

最后少了 一个  namespace没有关闭

TOP

长夜漫漫,我以为我睡不着,原来野比老师也没睡呢。。呵呵。。

TOP

发新话题