Cast object to Decimal nullable

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

    Cast object to Decimal nullable

    Hi all
    how can I write a method that returns me true if is possible to cast an
    object to decimal nullable and false if not?
    Like

    public bool CanConvert(obje ct obj)
    {

    return true if obj is possible to cast to decimal nullable
    return false if not

    }

    Thanks a lot.
    --
    Luigi

  • Jon Skeet [C# MVP]

    #2
    Re: Cast object to Decimal nullable

    On Oct 31, 3:20 pm, Luigi <ciupazNoSpamGr a...@inwind.itw rote:
    how can I write a method that returns me true if is possible to cast an
    object to decimal nullable and false if not?
    Like
    >
    public bool CanConvert(obje ct obj)
    {
    return true if obj is possible to cast to decimal nullable
    return false if not
    }
    public bool CanConvert(obje ct obj)
    {
    return obj is decimal || obj == null;
    }

    Comment

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

      #3
      Re: Cast object to Decimal nullable

      "Jon Skeet [C# MVP]" wrote:
      public bool CanConvert(obje ct obj)
      {
      return obj is decimal || obj == null;
      }
      Perfect, thank you Jon.

      Luigi

      Comment

      Working...