###### 想通过递归来进行汇流积累量,但是运行过程中出现错误System.StackOverflowException:“Exception_WasThrown”,请问各位大佬怎么处理
public static double Get_Flow(int i, int j, double[,] result, double[,] a, int[,] index, double[] FlowDirect)//获取第一次运行后得到的汇流值
{
int M = a.GetLength(0);
int N = a.GetLength(1);
int ni, nj;
if(a[i, j] == 0)
{
return 0;
}
for (int n = 0; n < 8; n++)
{
ni = i + index[n, 0];
nj = j + index[n, 1];
if (ni >= 0 && ni < M && nj >= 0 && nj < N)
{
if (a[ni, nj] == FlowDirect[n])
{
result[i, j] = 1 + Get_Flow(ni, nj, result, a, index, FlowDirect);
}
}
}
return result[i,j];
}
public static double[,] Flow_Acc(double[,] Fill)
{
#region 设置参数
int[,] index = new int[8, 2];
double[] FlowDirect = new double[8];
index[0, 0] = -1;
index[0, 1] = 0;
index[1, 0] = -1;
index[1, 1] = 1;
index[2, 0] = 0;
index[2, 1] = 1;
index[3, 0] = 1;
index[3, 1] = 1;
index[4, 0] = 1;
index[4, 1] = 0;
index[5, 0] = 1;
index[5, 1] = -1;
index[6, 0] = 1;
index[6, 1] = -1;
index[7, 0] = -1;
index[7, 1] = -1;
FlowDirect[0] = 64;
FlowDirect[1] = 128;
FlowDirect[2] = 1;
FlowDirect[3] = 2;
FlowDirect[4] = 4;
FlowDirect[5] = 8;
FlowDirect[6] = 16;
FlowDirect[7] = 32;
#endregion
int m = Fill.GetLength(0);
int n = Fill.GetLength(1);
double[,] result = new double[m, n];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
result[i, j] = Get_Flow(i, j, result, Fill, index, FlowDirect);
}
}
return result;
}