【发布时间】:2023-04-05 15:53:01
【问题描述】:
亲爱的,
我创建了一个方法,该方法将在使用 ref 选项填充三个数组后检索它们
出现以下错误“System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'”
代码如下。我该如何解决它
namespace ConsoleApp9
{
class Program
{
public static int getarrays(ref string[] patternName, ref int[] loadindex, ref double[] loadFactor)
{
int status = 0;
for (int i = 0; i < 4; i++)
{
patternName[i] = "test";
}
for (int i = 0; i < 5; i++)
{
loadindex[i] = i;
}
for (int i = 0; i < 8; i++)
{
loadFactor[i] = i/10;
}
return status;
}
static void Main(string[] args)
{
string[] ptt = new string[1];
int[] index = new int[1];
double[] factor = new double[1];
getarrays(ref ptt,ref index, ref factor);
}
}
}
【问题讨论】: