| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1251 人关注过本帖
标题:求各位指点这段调用函数的代码哪错了
只看楼主 加入收藏
causticsoda
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-2-27
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
求各位指点这段调用函数的代码哪错了
namespace ConsoleApplication8
{
    class program
    {
        static int MaxValue(int[] intArray, out int maxIndex)
        {
            int maxVal = intArray[0];
            maxIndex = 0;
            for (int i = 1; i < intArray.Length; i++)
            {
                if (intArray[i] > maxVal)
                {
                    maxVal = intArray[i];
                    maxIndex = i;
                }
                return maxVal;
            }
        }
        static void Main(string[] args)
        {
            int[] myArray = { 1, 8, 3, 6, 2, 5, 9, 3, 0, 2 };
            int maxIndex;
            Console.WriteLine("The maximum value in myArray is {0}",MaxValue(myArray,out maxIndex));
            Console.WriteLine("The first occurrence of this value is at element {0}", maxIndex + 1);
        
        }
        //I dont know where the problems lies.
    }
}
-------------------------------------------------------------------------------------------------------------
功能是找出最大值。
报错窗口
not all code paths return a value.

感激不尽!
搜索更多相关主题的帖子: return 
2017-02-27 17:01
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:20 
如果代码没有进入for循环,这时该怎么办呢,提示你并非所有代码路径都有返回值
2017-03-02 00:24
快速回复:求各位指点这段调用函数的代码哪错了
数据加载中...
 
   



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

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