c# - Getting an specific item from List<> -
i have problem! have found allots of people same problem none of answers helpt me.. im trying specific item list<> result of "test" returns null, why?
public mainwindow() { initializecomponent(); var modellist = new model2(); modellist.mypropertylist.add(new model1 { name = "hej1", myproperty1 = true }); modellist.mypropertylist.add(new model1 { name = "hej2", myproperty1 = false }); var test = modellist.mypropertylist.find(x => x.name == "hej1").myproperty1; }
according op comments
how know null? – dotctor 1 hour ago
when debug value null.. – dennis eriksson 1 hour ago
are sure check value after executing line? try adding `messagebox.show(test.tostring());) , see result – dotctor 1 hour ago
i feel shame of question.. working whole time! fault read value before declared "test"! thanks!! – dennis eriksson 1 hour ago
i think problem in way debugged program. have put breakpoint on line var test = modellist.mypropertylist.find(x => x.name == "hej1").myproperty1;
, execution stops right before line but think line executed , visual studio shows value of test
null
in autos window , makes think test
null. if continue execution pressing f10
or add line messagebox.show(test.tostring());
make previous line executed or somehow show value of test
find not null
.
Comments
Post a Comment