471,627 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

I need you help...experts...

a
Dear All Experts

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

??

thanks

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

Thanks a look

Jan 23 '06 #1
2 1130
Sounds suspiciously like homework to me...

The details of object.ToString and Convert.ToString(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
Jan 23 '06 #2
> if the object is null
which one will not flow exception? all of them can throw exception,
however, AFAIR of object is equal to null then (string)object will return
null.

Convert.ToString(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
http://vadmyst.blogspot.com

"a" <?a?@?l.???q> wrote in message
news:Oz*************@tk2msftngp13.phx.gbl... Dear All Experts

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

??

thanks

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

Thanks a look

Jan 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by abcd | last post: by
12 posts views Thread by Vibhajha | last post: by
11 posts views Thread by blah | last post: by
22 posts views Thread by OHM \( Terry Burns \) | last post: by
5 posts views Thread by Kevin Carne | last post: by
51 posts views Thread by cool_ratikagupta | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.