Casting to string versus calling ToString

  • (string)obj casts obj into a string. obj must already be a string for this to succeed.
  • obj.ToString() gets a string representation of obj by calling the ToString() method. Which is obj itself when obj is a string. This (should) never throw(s) an exception (unless obj happens to be null, obviously).

So in your specific case, both are equivalent.

Note that string is a reference type (as opposed to a value type). As such, it inherits from object and no boxing ever occurs.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)