I'm developing with C#, Visual Studio 2017 and .NET Framework 4.7.1.
My program do a lot of calculations, and I don't want to create new Collections to store them. So, I have created a collection to reuse it (the only thing that I'm going to do is change the collection's content):
List<List<double>> offsprings;
Inside the following method I will clean the contents of offsprings
parameter to not create new 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;
}
}
}
My question is: Which is the best way to return offspring
parameter?
Now, the method works, but I'm not sure if this is the right way to do it.