Mar*_*ers 20

是的,有区别.每个对象都有一个ToString方法,但不是每个对象都可以强制转换为字符串.

int i = 10;
string s1 = i.ToString(); // OK
string s2 = (string)i;    // Compile error.

object o = 10;
string s3 = o.ToString(); // OK
string s4 = (string)o;    // Runtime error.
Run Code Online (Sandbox Code Playgroud)


Sou*_*sou 12

ToString()当对象是null,引发异常时,(string)转换不会.