【发布时间】:2015-10-22 18:27:00
【问题描述】:
我遇到了一个问题,我将我的第一个数组放入了一个名为 DisplayArray1() 的公共方法中,我已经编译了它,当我打开可执行文件时显示“由于 StackOverflowException 而终止进程” ?有没有其他人遇到过这个问题?
这是我目前的代码:
using System;
namespace FlexibleArrayMethod
{
class Program
{
static void Main()
{
Console.Clear();
// Call intDisplayArray1() to output on screen
intDisplayArray1();
Console.Write("Array 1: ");
}
public static int intDisplayArray1()
{
// first array declaration
int[] Array1 = {5, 10, 15, 20};
return intDisplayArray1[];
}
}
}
感谢任何帮助!
【问题讨论】:
-
你是怎么编译的?
return intDisplayArray1[];无效。 -
你能解释一下你想达到什么目标吗?
-
我想你的真实代码是
return intDisplayArray1();,但看起来你的意思是return Array1;。 -
我通过命令行编译了所有内容。编译时也没有出现错误,所以老实说我不确定你是否说它无效。我试图创建一个基于控制台的应用程序,它声明了 3 个不同大小的数组。然后将每个数组传递给一个方法,该方法显示每个数组中的所有整数及其总和。
-
@AlyBee 我喜欢你的评论,因为你诚实地说出了你想要的。 :-)
标签: c# arrays methods stack-overflow