Casting problem on decimal nullable

  • Thread starter Thread starter Luigi
  • Start date Start date
L

Luigi

Hi all,
I have this snippet that don't compile:

Math.Ceiling(-voceValue.Value - 0.5M);

because the field Value of the class voceValue is decimal nullable.

How can I solve?

Thanks a lot.
 
Well, you need to know what you want to do if it is null. You can
check first with HasValue, or use can use .Value (i.e. .Value.Value)
or a cast to assert that it is non-null, or you can
use .GetValueOrDefault [using zero or your own default].

Marc
http://marcgravell.blogspot.com/
 
Marc Gravell said:
Well, you need to know what you want to do if it is null. You can
check first with HasValue, or use can use .Value (i.e. .Value.Value)
or a cast to assert that it is non-null, or you can
use .GetValueOrDefault [using zero or your own default].

Hi Marc,
GetValueOrDefault is only for C# 3.0?
Actually I'm using C# 2.0.
I'm trying with .HasValue.

Luigi
 
Marc Gravell said:
Well, you need to know what you want to do if it is null. You can
check first with HasValue, or use can use .Value (i.e. .Value.Value)
or a cast to assert that it is non-null, or you can
use .GetValueOrDefault [using zero or your own default].

GetValueOrDefault is only for C# 3.0?
Actually I'm using C# 2.0.
I'm trying with .HasValue.

GetValueOrDefault has been in System.Nullable<T> since .NET 2.0. (It's
a framework thing, not a language thing.)

Jon
 
Back
Top