c# - Null Object Reference Error -
this question has answer here:
- what nullreferenceexception, , how fix it? 29 answers
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
Post a Comment