The basic difference between them is the Convert function handles NULLS while i.ToString () does not; it will throw a NULL reference exception error. So as good coding practice using convert is always safe.
Convert.ToString() return an empty string if the object is null.
ToString it will throw a NULL reference exception error.
Example:
string i = null;
Console.Write(i.ToString()); // it throw a NULL reference exception error.
Console.Write(Convert.ToString(i)); // it return an empty string
No comments:
Post a Comment