The code you've provided is unusable as it contains unknown variables and most likely the "crash" is caused by logic within the loop not the loop itself.
class Program
{
private static readonly Random _random = new Random();
static void Main(string[] args)
{
double lowPrice = 2.2d;
double Ncma = 8;
List<double> items = PopulateList(10);
items.ForEach(i => {
double value = (i - lowPrice) / (Ncma - lowPrice);
Console.WriteLine(value);
});
}
public static List<double> PopulateList(int iterations)
{
List<double> items = new List<double>();
for (int i = 0; i< iterations; i++)
{
items.Add(i + _random.Next(100));
}
return items;
}
}
Unfortunately no. Tried to remove some lines and move some script. Displace called variables. Nothing yet.
Hi FranKDuc-4126,
Since you cannot provide the code that caused the crash, we cannot determine the specific cause of the crash. As AgaveJoe said, the "crash" is probably caused by the logic within the loop rather than the loop itself.
For your initial question, you can change the for loop you provided to the following linq.
Best Regards,
Daniel Zhang
It wont solve the problem because that method cant be applied in my case. But thanks for noticing it.
Hi @FranK Duc ,
To solve your actual problem, more relevant code to reproduce the problem is still necessary.
Best Regards,
Daniel Zhang
Sign in to comment