• How to avoid null reference exception in C# ?

    Abhey Member

    How to avoid null reference exception in C# ?
    I want to either return the value or 0 if it is null

    get { return string.Format("{0:C}", MyMonetaryValue); }

  • SapnaVishwas Member

    Try it like this

    get { return string.Format("{0:C}", (MyMonetaryValue != null) ? MyMonetaryValue : 0); }

Viewing 1 reply thread
  • You must be logged in to reply to this topic.