标题:代码有一处错误。请教
取消只看楼主
哈哈飞
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-10-31
 问题点数:0 回复次数:0 
代码有一处错误。请教
如下是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;
               
                }
            
            }
        }
     }
搜索更多相关主题的帖子: using System int 代码 MAXi 
2008-04-19 01:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-209865-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.639282 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved