ToString() returns only a value, which is representing the object like
int.ToString() returns the value as a string or somtemis it returns the type
or name or somethin else.
with the cast (string) you cast the object into a string object.
--
Mit freundlichen Grüßen -- Regards
Ralph Gerbig
www.ralphgerbig.de.vu
ikea....@web.de
"Ralph Gerbig" <ikea....@web.de> wrote in message
news:%236f3R71...@tk2msftngp13.phx.gbl...
msg = i.ToString(); // Kopies the value i has into msg
msg = (string)i; // Trys to cast i into a string object and copy a pointer
into msg (this statement won't work)
o = msg; // copys a pointer on msg into o (no explicit cast is needed
because string is inherited from System.Object)
there is a huge diference in copying a pointer and changing a value.
--
Mit freundlichen Grüßen -- Regards
Ralph Gerbig
www.ralphgerbig.de.vu
ikea....@web.de
"John Wood" <jwood8@go_ahead_remove_this.optonline.net> schrieb im
Newsbeitrag news:vRuZa.27871$_R5.7...@news4.srv.hcvlny.cv.net...
Thanks for clarifying.
"Ralph Gerbig" <ikea....@web.de> wrote in message
news:urlh0M2X...@TK2MSFTNGP09.phx.gbl...
>string msg;
>int i = 5;
>object o;
>
>msg = i.ToString(); // Kopies the value i has into msg
>msg = (string)i; // Trys to cast i into a string object and copy a pointer
>into msg (this statement won't work)
The difference that your comments describe does not exist. Both
ToString() and (string) generate a System.String that is (hopefully)
somehow based on the value of i. The second statement would work just
fine if i happened to be of a type that defines a typecast to string.
John Wood is correct, there really is no difference between the two
operations, and the compiler might easily map the string cast to the
ToString method by default.
--
http://www.kynosarges.de
Chris
"John Wood" <jwood8@go_ahead_remove_this.optonline.net> wrote in message
news:h%tZa.27588$_R5.7...@news4.srv.hcvlny.cv.net...