c# - List in class is null even though I made an instance of the class -
i'm trying access list personal
functions in main programme maintain getting it's not instance of...
the class code:
[serializable()] class faktnr { public int lopnummer; public int year; public list<string> personal = new list<string>(); public faktnr() { personal = new list<string>(); } }
the form code:
public partial class form1 : form { internal faktnr faktnr = new faktnr(); public form1() { initializecomponent(); } private void laggtillperson_click(object sender, eventargs e) { faktnr.personal.add(combobox1.text); }
code shortened here shows essentials. nullreferenceexception occurs in function laggtillperson_click
.
i want add together not combobox problem since tried this: faktnr.personal.add("uhiouh");
you getting exception on combobox1.text
, combobox1
null, not list personal
, seek replacing code with:
faktnr.personal.add("test string");
and see if still exception.
you accessing text
property of combobox, instead may utilize combobox.selectedtext property
or can check null in event:
private void laggtillperson_click(object sender, eventargs e) { if(combobox1 != null) faktnr.personal.add(combobox1.text); }
c# winforms
No comments:
Post a Comment