| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1861 人关注过本帖
标题:在C#中如何调用含数组的方法?
取消只看楼主 加入收藏
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
在C#中如何调用含数组的方法?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 输入三个double类型的数
{
    public class score
    {
        double[] scores;
        
        public double XunXu(double[] score)
        {
            this.scores[3]=score[3];
            int i;
            int j;
            double  t;
            for (i=0;i<2;i++)
                for (j = i - 1; j < 3; j++)
                {
                    if (scores[i] <scores[j])
                    {
                        t = scores[i];
                        scores[i] = scores[j];
                        scores[j] = t;
                     
                    }
                }
            return scores[3];
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int i;
            score s = new score();
            double Shu;
            double[] a=new double[3];
            Random rand = new Random();
            for (i = 0; i < 3; i++)
            {
                a[i] = rand.Next(100);
            }
            Shu = s.XunXu(double[] a);不知道该如何调用数组的函数???求路过的朋友帮忙!!
            for (i = 0; i < 3; i++)
            {
                Console.WriteLine(a[i]);
            }
        }
    }
}
搜索更多相关主题的帖子: namespace public double scores 
2013-05-07 13:34
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
收藏
得分:0 
出现异常了,得不了结果!!!!

你不勇敢,谁替你坚强。。。
2013-05-07 15:27
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
收藏
得分:0 
还不得
this.scores[3]=score[3];
索引超出了数组界限。不知道该怎么改???

你不勇敢,谁替你坚强。。。
2013-05-07 15:41
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
收藏
得分:0 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 输入三个double类型的数
{
    public class score
    {
      
        public double[] scores=new double[4];

           public  double XunXu(double[] score1)
            {
                int i;
                int j;
                double t;
                this.scores[4] = score1[4];
未处理 System.IndexOutOfRangeException
  Message="索引超出了数组界限。"
  Source="输入三个double类型的数"
  StackTrace:
       在 输入三个double类型的数.score.XunXu(Double[] score1) 位置 G:\c#程序\输入三个double类型的数\输入三个double类型的数\Program.cs:行号 18
       在 输入三个double类型的数.Program.Main(String[] args) 位置 G:\c#程序\输入三个double类型的数\输入三个double类型的数\Program.cs:行号 50
       在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       在 System.Threading.ThreadHelper.ThreadStart()
  InnerException:

                for (i = 0; i < 2; i++)
                    for (j = i + 1; j < 3; j++)
                    {
                        if (scores[i] < scores[j])
                        {
                            t = scores[i];
                            scores[i] = scores[j];
                            scores[j] = t;

                        }
                    }
                return scores[3];
            }

      
    }

    class Program
    {
        static void Main(string[] args)
        {
            int i;
           
            score s = new score();
            double Shu;
            double[] a=new double[4];
            Random rand = new Random();
            for (i = 0; i < 3; i++)
            {
                a[i] = rand.Next(100);
            }
            Shu = s.XunXu(a);
            for (i = 0; i < 3; i++)
            {
                Console.WriteLine(a[i]);
            }
        }
    }
}


还是不会改???

你不勇敢,谁替你坚强。。。
2013-05-07 17:47
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
收藏
得分:0 
我不太会用数组,可以详细一点吗???拜托咯!!!!

你不勇敢,谁替你坚强。。。
2013-05-07 17:52
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
收藏
得分:0 
好叻!!ok啦...谢谢以上朋友的帮忙!!

你不勇敢,谁替你坚强。。。
2013-05-08 13:05
快速回复:在C#中如何调用含数组的方法?
数据加载中...
 
   



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

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