c# - Null Object Reference Error -


this question has answer here:

i created class below

public class table {    public enum columnnames    {        id,        tablename,        active,        date    }     public list<tableparameter> parameters { get; set; } }  public enum types {     int,     string,     datetime,     boolean,     decimal }  public class tableparameter {     public table.columnnames parametername { get; set; }     public types? tip { get; set; }     public dynamic value { get; set; } } 

when try use below, i'm getting null object reference error.

table tb3 = new table(); tb3.parameters.add(new tableparameter() { parametername = table.columnnames.id, value = 1, tip = types.int }); 

hope me. i'll wait answer.

you need initialize tb3.parameters

table tb3 = new table(); tb3.parameters = new list<tableparameter>(); tb3.parameters.add(new tableparameter() { parametername = table.columnnames.id, value = 1, tip = types.int }); 

or can initialize in table class constructor below

public class table {   public table()   {      parameters = new list<tableparameter>();   } } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -