c# - 如何返回已在方法内修改的对象?
问题描述
我正在使用 C#、Visual Studio 2017 和 .NET Framework 4.7.1 进行开发。
我的程序做了很多计算,我不想创建新的集合来存储它们。所以,我创建了一个集合来重用它(我唯一要做的就是更改集合的内容):
List<List<double>> offsprings;
在以下方法中,我将清除offsprings
参数的内容以不创建新的List<double>
:
public void GlobalRecombination(
List<List<double>> population,
List<List<double>> offsprings,
int numOfObjectVariable,
int numOfStrategyParameters,
RecombinationType objVarRecomType,
RecombinationType straParamRecomType)
{
foreach (List<double> offspring in offsprings)
{
offspring.Clear();
for (int i = 0; i < numOfObjectVariable; i++)
{
double newValue = 0.0;
[ ... ]
offspring[i] = newValue;
}
int total = numOfObjectVariable + numOfStrategyParameters;
for (int i = numOfObjectVariable; i < total; i++)
{
double newValue = 0.0;
[ ... ]
offspring[i] = newValue;
}
}
}
我的问题是:返回offspring
参数的最佳方式是什么?
现在,该方法有效,但我不确定这是否是正确的方法。
解决方案
推荐阅读
- java - 使用抽象源 [java] 进行数据访问 - 用于傻瓜
- angular-components - 是否可以展开/折叠 MaterialListComponent 中的项目
- html - 显示图片来源
- java - 算法可视化:实现没有循环但每次调用函数时增量可变的插入排序
- java - 从休眠实体构造 SQL 保存、更新、删除查询?
- javascript - 一行中有多个语句的箭头函数
- rule-engine - 如何根据规则 if 子句中定义的属性值过滤数据源列表
- swift - 当响应数据不包含要使用 Combine 解码的对象时,我怎么能抛出错误?
- php - Symfony - 在 Bundle 内创建自己的配置(service.yaml)
- elasticsearch - Elasticsearch 通过增强和模糊搜索跨领域