I have two lists in my program that the length of the lists is not equal. I want to subtract the members of these two lists element by element and save them in one list.
List<double> arrivals = new List<double>();
List<double> departure = new List<double>();
List<double> delays = new List<double>();
double departure_p = 0.8;
double arrival_p = 0.45;
int slot = 0;
while (slot < 1000)
{
Random a = new Random();
double arrival_t = a.NextDouble();
Random d = new Random();
double departure_t = d.NextDouble();
if (departure_t <= departure_p)
{
departure.Add(departure_t);
}
if (arrival_t <= arrival_p)
{
arrivals.Add(arrival_t);
}
slot++;
}
When I use this method I encounter the exception system.IndexOutOfRangeException.
for (int i = 0; i <= arrivals.Count; i++)
{
delays.Add(departure[i] - arrivals[i]);
}
foreach (var item in delays)
Console.WriteLine(item);
How can I do this?