我是一个初学者,看书时有个示例代码,键入后报错,查找不到原因,请高手帮忙看一下,代码如下:
using System;class MyA1
{
static int MaxValus( int[] args , out int maxIndex)
{
int maxValue = 0 ;
maxIndex = 0;
for(int i=1 ; i<args.Length ; i++)
{
if (maxValue < args[i])
{
maxValue = args[i];
maxIndex = i;
}
return maxValue; }
}
static void Main(string[] args)
{
int[] MyArgs = {9,3,5,2,10};
int maxIndex;
Console.WriteLine("MaxValue is {0}}",MaxValus(MyArgs,out maxIndex));
Console.WriteLine("MaxIndex is {0}",maxIndex);
Console.ReadKey();
}
}代码的作用是取得数组的最大值和最大值的下标.现程序报错如下:
1.MaxValus并非所有的代码路径都返回值.
2. for(int i=1 ; i<args.Length ; i++) 此行代码的i++语句提示"检测到无法访问的代码"
请各位指点一下,是何原因? 多谢.
using System;class MyA1
{
static int MaxValus( int[] args , out int maxIndex)
{
int maxValue = 0 ;
maxIndex = 0;
for(int i=1 ; i<args.Length ; i++)
{
if (maxValue < args[i])
{
maxValue = args[i];
maxIndex = i;
}
return maxValue; }
}
static void Main(string[] args)
{
int[] MyArgs = {9,3,5,2,10};
int maxIndex;
Console.WriteLine("MaxValue is {0}}",MaxValus(MyArgs,out maxIndex));
Console.WriteLine("MaxIndex is {0}",maxIndex);
Console.ReadKey();
}
}代码的作用是取得数组的最大值和最大值的下标.现程序报错如下:
1.MaxValus并非所有的代码路径都返回值.
2. for(int i=1 ; i<args.Length ; i++) 此行代码的i++语句提示"检测到无法访问的代码"
请各位指点一下,是何原因? 多谢.
解决方案 »
- DateTime.Parse转换问题
- C# 模拟键盘问题,求解!
- 关于面向对象的类属性归类?设计类?
- 有关.ShowDialog() 打开窗体,关闭问题
- Directory.GetFileSystemEntries()报目录名无效。。help..
- DoEvents()执行后为什么会从方法从跳出来呢?
- GDI+画的简单坦克演示游戏中,在按下空格键后如何出现子弹,并且子弹能不断前行,需要用定时器吗?
- 如何改变DataGrid里的特定行的背景色或前景色?
- 如何用c#写一个可在外部接收事件的winform控件?
- 初学者提问:在c#中网络传输的问题。
- form问题,急~~~救命啊!!!
- 如何把数据缓存到dataset里面?
{
static int MaxValus( int[] args , out int maxIndex)
{
int maxValue = 0 ;
maxIndex = 0;
for(int i=1 ; i <args.Length ; i++)
{
if (maxValue < args[i])
{
maxValue = args[i];
maxIndex = i;
} }
return maxValue;
}
static void Main(string[] args)
{
int[] MyArgs = {9,3,5,2,10};
int maxIndex;
Console.WriteLine("MaxValue is {0}}",MaxValus(MyArgs,out maxIndex));
Console.WriteLine("MaxIndex is {0}",maxIndex);
Console.ReadKey();
}
}