What is the difference between distinguishing Int from a string and the ToString () method?
For example: -
int MyInt = 10; label1.Text = (string)MyInt; // This Doesn't Work label1.Text = MyInt.ToString(); // but this does.
Well, ToString()it's just a method call that returns a string. It is defined in object, so it is always valid to call anything (other than a null reference).
ToString()
object
A cast operator can perform one of four tasks:
int
byte
string
int string. , .
, , int , .
ToString() int, :)
Um, ToString() , .
, , , ( ), .
, , ( ), , , , .
, , Int32 String.
.ToString() - , System.Object( .NET) .
"int" .ToString(), ints .
(string) myint , / ( int ). , , int .
, , , int , .ToString() , int , !
ToString() , , Java, , Object.
Object
, # :
public override string ToString()
, Object . , , .
, , ToString , , # - Struct Int32.Int32 , , ToString().
Int32
One more thing never uses .ToString () if you think the object may be null or your application will judge an example:
// Emulates a problem that may happenobject obj = null; obj.ToString ();
Source: https://habr.com/ru/post/1705780/More articles:How do you check the performance of your website from different places around the world? - performanceShow large images with DirectX faster? - user-interfaceIIS Silverlight does not connect to WCF - silverlightGoogle Chrome breaks when onfocus sets size selection - javascriptCan the free edition of Soapui argue between the findings? - web-servicesTime Zones - timezoneTweaking asp.net mvc - asp.net-mvcDifference between CFRunLoopRemoveSource and CFRunLoopSourceInvalidate - crashHow can I create a client proxy for a WCF service with an HTTPS endpoint? - securityHow to get a bug report from the "Please tell Microsoft about it" dialog? - windows-xpAll Articles