c# - 为什么返回数组在c#的函数中不起作用
问题描述
我正在为学校编写一个项目,但在编写代码时遇到了问题。我试图在一个数组中返回 2 个整数,但它对我不起作用......有人可以帮助我吗?
public static int[] generation(char[,] people)
{
int neighbors = 0;
int[] changes = new int[2];
changes[0] = 0; //alive
changes[1] = 0; // dead
for (int i = 0; i < people.GetLength(0); i++)
{
for (int j = 0; j < people.GetLength(1); j++)
{
neighbors = cell_state(i, j - 1, people) + cell_state(i, j + 1, people) + cell_state(i + 1, j, people) + cell_state(i - 1, j, people) + cell_state(i - 1, j - 1, people) + cell_state(i + 1, j + 1, people) + cell_state(i - 1, j + 1, people) + cell_state(i + 1, j - 1, people);
if (neighbors <= 1)
{
people[i, j] = '+';
changes[1] =+ 1;
}
if (neighbors > 3)
{
people[i, j] = '+';
changes[1] =+ 1;
}
if (neighbors == 3)
{
people[i, j] = '0';
changes[0] =+ 1;
}
}
}
return changes;
}
然后我主要写了这个:
int[] changes = new int[2];
changes = generation(people);
born_counter = changes[0];
died_counter = changes[1];
有人可以帮助我吗?
解决方案
推荐阅读
- php - 如何将全局变量注入所有模板?
- python - Tkinter Text Widget Ctrl+A + DEL 删除标签
- python-3.x - 是否可以从 Process 对象中取回目标?
- ruby - Ruby TCPServer 未侦听 Google Cloud Platform 上的端口
- python - 如何使用策略“均值”拟合缺失值?
- node.js - 在 GKE 上的 StatefulSet 中运行的 node.js API 上的 SSL
- scope - 变量的生命周期和范围不相关的场景
- sap - 原因:org.hsqldb.HsqlException:用户缺少权限或找不到对象:DUMMY / Invalid schema SYS
- laravel - Laravel - 从模型急切加载时获取列名
- java - 为移动应用创建 ApiKey 和 SecretKey