The Artima Developer Community
Sponsored Link •

C# Answers Forum
Short and null

2 replies on 1 page. Most recent reply: Aug 23, 2005 6:44 PM by Joe Merlino

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
giciorek

Posts: 16
Nickname: gicio
Registered: Dec, 2002

Short and null Posted: Mar 13, 2005 9:32 AM
Reply to this message Reply
Advertisement
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


Hari Vignesh Padmanaban

Posts: 2
Nickname: vignesh
Registered: May, 2005

Re: Short and null Posted: May 28, 2005 1:29 PM
Reply to this message Reply
Hi,
I think you are getting null becos your "myObject" is null and not becos "MyShortProperty" is snull

Make sure that myObject is not null before you test for its property :)

Joe Merlino

Posts: 4
Nickname: ooforever
Registered: Aug, 2005

Re: Short and null Posted: Aug 23, 2005 6:44 PM
Reply to this message Reply
Not sure if this is what you are getting at but a short can't be null. As a public property coupled with a private class variable its initialized to 0. A way to overcome this is to have a common library or assembly that defines all primitive types null values to be say short.minvalue. When you're getting the null value from a database, set the property to that value. This of course would need to be tested by the controller or ui layer and handled accordingly in the UI. On the way back into the database the dataaccess layer would then prepare the parameter for this value and set it to the db type null for that type so that it will be represented as NULL in the database table.

Flat View: This topic has 2 replies on 1 page
Topic: working with arguments Previous Topic   Next Topic Topic: Fileystem error

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use