Pages

2010/11/02

[C#] .toString與Convert.ToString 差異

object obj = null;
//  回傳空字串
Console.WriteLine("Convert.ToString: " + Convert.ToString(obj));
//  無回傳結果, 並產生NullReferenceException
Console.WriteLine("toString: " + obj.ToString());
Console.ReadKey();

No comments: