c# - Strange null-able member in derived WinForm -


i have following winforms hierarchy.

form ==> aform ==> bform 

and there null-able member int? x; defined in aform. , in bform, there following code.

public partial class bform : aform, ibview {     ......     public int y     {                 {             int z = x ?? 0;             system.diagnostics.debug.writeline("x: " + x.tostring() + " z: " + z.tostring());             return z;         }     } 

x shouldn't null. trying close , open form bform. works , z 0 (maybe once every 10 times). have conditional break z==0 on line return z.

when break point hit. debug write

    x:  z: 0 

but value of x neither null nor 0 when hover mouse cursor on x in visual studio after break point hit.

if x nullable - i.e. int? x - then, it's value obtained via x.value. can check:

int z = x.hasvalue ? x.value : 0; 

optionally, may cast x - (int)x - want check if x.hasvalue first. otherwise, believe null exception if x has not yet been initialized.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -