Casting vs Converting an object toString, when object really is a string

The two are intended for different
purposes. The ToString method of any
object is supposed to return a string
representation of that object. Casting
is quite different, and the ‘as’ key
word performs a conditional cast, as
has been said. The ‘as’ key word
basically says “get me a reference of
this type to that object if that
object is this type” while ToString
says “get me a string representation
of that object”. The result may be the
same in some cases but the two should
never be considered interchangeable
because, as I said, they exist for
different purposes. If your intention
is to cast then you should always use
a cast, NOT ToString.

from http://www.codeguru.com/forum/showthread.php?t=443873

see also http://bytes.com/groups/net-c/225365-tostring-string-cast

Leave a Comment