I have a list its name is TP that may be a null or has data, and have a list of list vairable its name is history.
I want to add the TP list to history with help of a counter "winc".
int winc = 1;
List TP ;
List
List
- > history = new List
- >() ;
When I run the code below gives exception invalid index or arument "An ArgumentOutOfRangeException"
history[winc-1].AddRange (TP.ToList ());
winc++;
I slould say in first time my TP list is null and TP.count() is 0.
Please help
Thanks
VulpesPosted Aug 25, 2013, 11:22 AM
history.Add(TP);
and the elements will automatically be given the correct index.
However, if history already has elements and you want to replace the one at index winc -1, you can do:
history[winc - 1] = TP;
Finally, if history already has elements but you want to insert one at index winc -1, you can do:
history.Insert(winc - 1, TP);
Notice that, if TP is not null, it should refer to a different List
VulpesPosted Aug 25, 2013, 12:52 PM
Just use history.Add(TP). TP will then be added at index history.Count which, of course, will be 0 to start with.
diamond diamondPosted Aug 25, 2013, 12:44 PM
TP takes its data from this db and sc.
List
Vulpes, I changed my code to history[winc - 1] = TP; but, still gives an exception
My history does not already any data. winc is counter for time window I want TP in every time windows dropped to history and I specified contains of history with time window. It means which tp list realated to which time window in history.
I tested this was ok,
history.Insert(winc - 1, TP);
Thanksssss Vulpes
Arpit JainPosted Aug 25, 2013, 11:04 AM
List
And also i guess you need to do this only AddRange(TP); Because TP is already a list.