list - c#: Object reference not set to an instance of an object -


this part of code.

list<datetime>[] newarraydate1 = new list<datetime>[70]; datetime temp1 = arraydate1[k][aa]; newarraydate1[k].add(temp1); 

i used messagebox.show(temp1) , there value in temp1. error shown on first line of program.

when create array, create containing structure. members initializeded default values, in case of list<datetime> null. essentially, seventy null references, each 1 capable of holding list of datetime.

to fix this, should either assign new arrays in loop

list<datetime>[] newarraydate1 = new list<datetime>[70]; (int = 0 ; != newarraydate1.length ; i++) {     newarraydate1[i] = new list<datetime>(); } 

or use linq:

list<datetime>[] newarraydate1 = enumerable     .range(0, 70)     .select(n => new list<datetime>())     .toarray(); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -