Difference between Convert. ToString and ToString, convert. tostring
Convert. ToString can process null strings.
static void Main(string[] args)
{
string msg = null;
Console.WriteLine(Convert.ToString(msg));
Console.ReadKey();
}
Run without throwing an exception.
If the ToString method cannot process null strings, an exception is thrown.
static void Main(string[] args)
{
string msg = null;
//Console.WriteLine(Convert.ToString(msg));
Console.WriteLine(msg.ToString());
Console.ReadKey();
}
What is the difference between the ConvertToString () function and the ToString () method ??
It can be understood that. ToString () is the string type conversion of the class, not all classes have the tostring function.
Convert. ToString () is a forced type conversion. Regardless of 3721, Lao Tzu just wants to make your head square!
Different from ConvertToString (I), itostring ()
The implementation of ToString () is the same as that of Convert in C.
As for packing, it is estimated that the landlord is overconcerned.
1. There must be two different types of conversions to create the target object. Creates a string reference.
2. the boxing mentioned above usually exists in int to Int32 conversion. However, in C #, Int32 is a struct, not a value type in Java, but a relationship between a packaging class. Int only appears in the form of a simple keyword provided by C # Int32. After compiled as IL, it is still expressed as Int32.
Int32 definition:
Public struct Int32: IComparable, IFormattable,
IConvertible, IComparable <int>, IEquatable <int>