I need you help...experts...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ºa¤Ö

    I need you help...experts...

    Dear All Experts

    I would like to know what's the different between
    Convert.ToStrin g(object)
    object.ToString ()
    (string)object

    ??

    thanks

    if the object is null
    which one will not flow exception?

    Thanks a look



  • Marc Gravell

    #2
    Re: I need you help...experts. ..

    Sounds suspiciously like homework to me...

    The details of object.ToString and Convert.ToStrin g(object) can all be found
    on MSDN2 very easily. The former will always throw an exception if object is
    null, the latter may/may-not depending on the exact formatter used (in the
    overloaded form) [EFR].

    (string)object is a simple cast of the object to a string, so if object is
    null this will always succeed (since string is a reference type, and
    reference types can always accept null values). I wouldn't say it doesn't
    "flow exception", simply because there *is* no exception to flow in this
    case - however, it doesn't throw one, if that's what the question is.

    Or just say that the dog ate it ;-p

    (apols if I am wrong about the howework thing, but I'm feeling cynic today)

    Marc


    Comment

    • Vadym Stetsyak

      #3
      Re: I need you help...experts. ..

      > if the object is null[color=blue]
      > which one will not flow exception?[/color]
      all of them can throw exception,
      however, AFAIR of object is equal to null then (string)object will return
      null.

      Convert.ToStrin g(object) tries to convert object into string. For this it
      first checks if
      object supports convesion intefaces IConvertible and IFormattable and if not
      calls object.ToString () method.

      object.ToString (). if underlying type overrides ToString() method then it is
      used to obtain string value. If this method is not overriden then default
      object.ToString () is used, this method will return object's type name
      object.GetType( ).ToString();

      --
      Vadym Stetsyak aka Vadmyst
      Blog about software development, algorithms, network protocols, .NET, programming languages, tips & tricks, coding techniques and more.


      "ºa¤Ö" <?a?ã@?Ãl.???q > wrote in message
      news:Ozyzmk$HGH A.208@tk2msftng p13.phx.gbl...[color=blue]
      > Dear All Experts
      >
      > I would like to know what's the different between
      > Convert.ToStrin g(object)
      > object.ToString ()
      > (string)object
      >
      > ??
      >
      > thanks
      >
      > if the object is null
      > which one will not flow exception?
      >
      > Thanks a look
      >
      >
      >[/color]


      Comment

      Working...