gicio Posted March 13, 2005 Posted March 13, 2005 HI!! Let say I have an object and this object has a property of the type short. How I can check if someone set this property? When i try to check this like that: if( myObject.MyShortProperty != null ) { } I get an null reference exception. How I can check this without a null references exception? regards, gicio Quote
coldfusion244 Posted March 13, 2005 Posted March 13, 2005 It would help if you posted more code than that, sounds like you aren't instantiating an object. Quote -Sean
IngisKahn Posted March 13, 2005 Posted March 13, 2005 It would seem that myObject is null. Also a value type can never be null. If you want to check if a value type property has been set then just set a bool in the property set method. Quote "Who is John Galt?"
Leaders snarfblam Posted March 14, 2005 Leaders Posted March 14, 2005 If you are not the author of this class, then there is no way to see if the value has been set because a short can never be null. Alternatively (assuming that you are the author of this class), although I would not personally recommend this, you could declare both the property and the underlying variable it is stored in as type object which would be null until set to a short, but this can cause issues with types and introduce bugs. Best to go with the method recommended by IngisKahn. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.