Domanda

I am using the following code but getting error

Object reference not set to an instance of an object" on line 2.

System.Timers.Timer[] timer = new System.Timers.Timer[10];
timer[0].Elapsed += new ElapsedEventHandler(DoJob);

Why?

È stato utile?

Soluzione

you forget to initialize array's item

System.Timers.Timer[] timer = new System.Timers.Timer[10];
timer[0] = new System.Timers.Timer();
timer[0].Elapsed += new ElapsedEventHandler(DoJob);

Altri suggerimenti

Your first line creates an array. An array of Timer references. An array of Timer references that all have a value of null.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top