They do different things. They compile with different MSIL code, but in most cases they are likely to have the same result.
ToString is a method defined by Object , which is an integral base type for all objects. By default, it returns the type name of the object, but can (and often) be overridden by each type so that it returns a more meaningful string. For example, in your example, x is an Int32 object, and Int32 overrides ToString , so it returns "3" instead of the standard "System.Int32".
I'm not sure, but I suspect that when you concatenate "" & x , it distinguishes x from String , in which case it is a shortcut to enter "" & CType(x, String) or "" & CStr(x) . Each type can overload the casting operator, so it assumes that the type (in this case, Int32 ) overloaded the operator and therefore can be wrapped to a string. Indeed, he has and can.
Convert.ToString does different things depending on what kind of overload you are causing. If you pass it Int32 , it will just call the object ToString() method. However, if you pass it an Object , for example, it first checks to see if the object IConvertible or IFormattable . If so, it uses one of them, otherwise the ToString method is used. Thus, he tries, depending on the type of object that you are sending it, to determine what he considers the most likely way to get this type in a string.
As far as I prefer, I would say that x.ToString() is what you want to use most often if you don't have any other problem (it all depends on what you do with the object).
Steven doggart
source share