| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1861 人关注过本帖
标题:在C#中如何调用含数组的方法?
只看楼主 加入收藏
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:13 
在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
shangsharon
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
威 望:7
帖 子:221
专家分:1261
注 册:2012-3-25
收藏
得分:5 
Shu = s.XunXu(a);

直接就给他一个数组嘛,他要啥你就给啥.
2013-05-07 13:52
黄辉
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
lantian8134
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:8
帖 子:115
专家分:789
注 册:2013-1-11
收藏
得分:5 
数组的下标是从0开始的
double[] a=new double[3] //存3个double类型的值
a[0] //第1个
a[1] //第2个
a[2] //第3个
a[3] //第4个会报错(索引超出了数组界限),上面只定义了存3个值
2013-05-07 16:50
淡风丝雨
Rank: 2
等 级:论坛游民
帖 子:12
专家分:30
注 册:2013-4-16
收藏
得分:5 
数组的调用prarams修饰符就可以了。。。
2013-05-07 17:03
黄辉
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
csharpluntan
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:7
帖 子:197
专家分:1122
注 册:2013-4-24
收藏
得分:5 
路过啊

投之以桃,报之以李
2013-05-08 09:47
lantian8134
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:8
帖 子:115
专家分:789
注 册:2013-1-11
收藏
得分:0 
this.scores = score1;
2013-05-08 12:06
快速回复:在C#中如何调用含数组的方法?
数据加载中...
 
   



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

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