c# - Get Object reference not set to an instance of an object error from static member -


i have static class this:

  public static class applicationlist     {         public static list<applicationsmodel> applicationsmodels { get; set; }     } 

i want use applicationsmodels in class

   class program     {         static void main(string[] args)         {             getapplicationnamefromappconfigandaddtoapplicationlist();         }          private static void getapplicationnamefromappconfigandaddtoapplicationlist()         {             list<string> applicationname = configurationmanager.appsettings["appname"].split(',').tolist();              foreach (var variable in applicationname)             {                 applicationlist.applicationsmodels.add(new applicationsmodel { datetime = datetime.minvalue, name = variable });              }         }     } 

but applicationlist null , error

object reference not set instance of object. 

this static prpoerty , can't create instance form static prpoerty

enter image description here

well have

 public static list<applicationsmodel> applicationsmodels { get; set; } 

property not initialized.

can this, instead:

public static class applicationlist {     private static list<applicationsmodel> appmodel = new list<applicationsmodel>();     public static list<applicationsmodel> applicationsmodels      {         { return appmodel ;}     }      //don't think need set in case..      // add it, if need } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -