Hi I have created four lists with predefined size.
public DataTable lost_time(DataTable ev_tab)
{
var ev_start = new List<int>(new int[1439]);
var ev_stop = new List<int>(new int[1439]);
var ev_duration = new List<int>(new int[1439]);
var ev_validation = new List<int>(new int[1439]);
foreach (DataRow evrow in ev_tab.Select())
{
DateTime date_start = Convert.ToDateTime(evrow[0]);
DateTime date_stop = Convert.ToDateTime(evrow[1]);
int start_time = date_start.Hour * 60 + date_start.Minute -1;
int stop_time = date_stop.Hour * 60 + date_stop.Minute - 1;
int duration = Convert.ToInt32(evrow[2]);
for (int i = start_time; i == stop_time; i++)
{
ev_start.RemoveAt(i);
ev_start.Insert(i, start_time);
ev_stop.Insert(i, stop_time);
ev_duration.Insert(i, duration);
ev_validation.Add(1);
}
}
So my question is, how can I replace list element on specyfic position (all list elements starting from "start_time" to "stop_time" sholud be replaced with new values). I have tried diffrent ways as u can see in for loop but nothing works list still contain only 0 values. Maybe whole idea is wrong and i should try something else?
Example: start_time = 299, stop_time=304,duration=5, validation=1 (when i>=start_time & i<=stop_time for rest values should be 0)
Screen: 
>Solution :
The List<T> constructor that takes an integer parameter uses that value to define an internal capacity for its buffer. It doesn’t take that value to create a number of the elements of the type T.
In your context I would just use an array of a specific class that contains the four properties. You already know the number of elements required and it seems that you don’t need to resize it, thus the List has no great advantage over an array.
public class Slot
{
public int ev_start {get;set;}
public int ev_stop {get;set;}
public int ev_duration {get;set;}
public int ev_validation {get;set;}
}
Now I would declare an array of this class.
public DataTable lost_time(DataTable ev_tab)
{
Slot[] minutes = new Slot[1439];
....
This creates the array but all the elements are null, you still need to create each slot and its values. This could be done while you traverse the grid or just at the start, so for example you need these lines to have all the 1440 slot initialized to some default
for(int x = 0; x < 1439; x++)
slots[x] = new Slot();
If you don’t want to initialize here, but only while you traverse the grid then you should create the element inside the loop
for (int i = start_time; i <= stop_time; i++)
{
// remove the commented line if you want to create the
// slot element while traversing.
// if(slots[i] == null) slots[i] = new Slot();
slots[i].ev_start = start_time;
slots[i].ev_stop = stop_time;
slots[i].ev_duration = duration;
// Unclear
// slots[i].ev_validation = 1;
}
While it could be more efficient to initialize while looping it also introduces the problem of testing each element for null if you loop again over the array. So unless there is a real performance problem I prefer to initialize each element even those not used.