您的位置:首页 > 其它

Convert.ToString和ToString的区别

2014-08-12 15:57 459 查看
Convert.ToString能处理字符串为null的情况。

static void Main(string[] args)
{
string msg = null;
Console.WriteLine(Convert.ToString(msg));
Console.ReadKey();
}

运行,没有抛出异常。

ToString方法不能处理字符串为null的情况,会抛出异常。

static void Main(string[] args)
{
string msg = null;
//Console.WriteLine(Convert.ToString(msg));
Console.WriteLine(msg.ToString());
Console.ReadKey();
}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: