1.Convert.ToString能處理字符串為null的情況。
測試代碼如下:
|
1
2
3
4
5
6
|
static
void
Main(
string
[] args)
{
string
msg =
null
;
Console.WriteLine(Convert.ToString(msg));
Console.ReadKey();
}
|
運行,沒有拋出異常。
2.ToString方法不能處理字符串為null的情況,會拋出異常。
測試代碼如下:
|
1
2
3
4
5
6
7
|
static
void
Main(
string
[] args)
{
string
msg =
null
;
//Console.WriteLine(Convert.ToString(msg));
Console.WriteLine(msg.ToString());
Console.ReadKey();
}
|
運行結果如下:

