c# - object crashing say it is NULL -


this question has answer here:

i've created class

public partial class subrank {     private system.datetime startdatefield;      public system.datetime startdate     {                 {             return this.startdatefield;         }         set         {             this.startdatefield = value;         }     } } 

im trying create array of this...

subrank[] pastsubrank = new subrank[1]; pastsubrank[0].startdate = datetime.parse("2012-05-22"); 

but pastsubrank[0] crashing saying null....why this?

yes cause haven't instantiated class subrank before accessing it's property.

subrank[] pastsubrank = new subrank[1]; pastsubrank[0] = new subrank(); pastsubrank[0].startdate = datetime.parse("2012-05-22"); 

Comments

Popular posts from this blog

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -