Casting problem on decimal nullable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?THVpZ2k=?=

    Casting problem on decimal nullable

    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.
    --
    Luigi

  • Marc Gravell

    #2
    Re: Casting problem on decimal nullable

    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 .GetValueOrDefa ult [using zero or your own default].

    Marc

    Comment

    • =?Utf-8?B?THVpZ2k=?=

      #3
      Re: Casting problem on decimal nullable

      "Marc Gravell" wrote:
      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 .GetValueOrDefa ult [using zero or your own default].
      >
      Hi Marc,
      GetValueOrDefau lt is only for C# 3.0?
      Actually I'm using C# 2.0.
      I'm trying with .HasValue.

      Luigi

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Casting problem on decimal nullable

        On Nov 5, 10:15 am, Luigi <ciupazNoSpamGr a...@inwind.itw rote:
        "Marc Gravell" wrote:
        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 .GetValueOrDefa ult [using zero or your own default].
        >
        GetValueOrDefau lt is only for C# 3.0?
        Actually I'm using C# 2.0.
        I'm trying with .HasValue.
        GetValueOrDefau lt has been in System.Nullable <Tsince .NET 2.0. (It's
        a framework thing, not a language thing.)

        Jon

        Comment

        • Marc Gravell

          #5
          Re: Casting problem on decimal nullable

          GetValueOrDefau lt is only for C# 3.0?
          Actually I'm using C# 2.0.
          GetValueOrDefau lt is part or Nullable<Twhich ships with .NET 2.0

          Retrieves the value of the current Nullable&lt;T&gt; object, or a default value.


          Marc

          Comment

          • =?Utf-8?B?THVpZ2k=?=

            #6
            Re: Casting problem on decimal nullable

            "Marc Gravell" wrote:
            GetValueOrDefau lt is only for C# 3.0?
            Actually I'm using C# 2.0.
            >
            GetValueOrDefau lt is part or Nullable<Twhich ships with .NET 2.0
            >
            http://msdn.microsoft.com/en-us/libr...cw(VS.80).aspx
            Very weel, thank you Marc and Jon.

            Luigi

            Comment

            Working...