D
Dylan Phillips
I've often used Java's Numeric Wrapper Objects when numeric properties can have a null state. This is very useful with optional properties for which 0 has meaning. For example:
//Java Code
class SomeObject
{
protected Double _optionalAttribute;
public Double getOptionalAttribute
{return _optionalAttribute;}
public Double setOptionalAttribute (double someValue)
{_optionalAttribute = new Double(someValue);}
}
class SomeCode
{
public static void main(string[] args)
{
SomeObject object = new SomeObject();
if (object.getOptionalAttribute == null) {System.out.println("Attribute is not set");}
else
{
if (object.getOptionAttribute.doubleValue() == 0) {System.out.println("Attribute is set to zero");}
else {System.out.println("Attribute is set to" + object.getOptionalAttribute.toString());}
}
}
}
In C#, I cannot test a System.Double for null. Any ideas on how others have solved this? I've been avoiding it for about 3 weeks now, and my code is getting sloppy.
Thanks,
Dylan
//Java Code
class SomeObject
{
protected Double _optionalAttribute;
public Double getOptionalAttribute
{return _optionalAttribute;}
public Double setOptionalAttribute (double someValue)
{_optionalAttribute = new Double(someValue);}
}
class SomeCode
{
public static void main(string[] args)
{
SomeObject object = new SomeObject();
if (object.getOptionalAttribute == null) {System.out.println("Attribute is not set");}
else
{
if (object.getOptionAttribute.doubleValue() == 0) {System.out.println("Attribute is set to zero");}
else {System.out.println("Attribute is set to" + object.getOptionalAttribute.toString());}
}
}
}
In C#, I cannot test a System.Double for null. Any ideas on how others have solved this? I've been avoiding it for about 3 weeks now, and my code is getting sloppy.
Thanks,
Dylan