What's the difference between casting an int to a string and the ToString() method in C#

后端 未结 6 1703
北海茫月
北海茫月 2020-12-01 17:49

What\'s the difference between casting an Int to a string and the ToString() method ?

For example :-

int MyInt = 10;
label1.Text = (string)MyInt;             


        
6条回答
  •  情话喂你
    2020-12-01 18:00

    One more thing never use .ToString() if you think the object might be null or your application will crach example :

    //Emulates the problem that might happen
    object obj = null; obj.ToString();

提交回复
热议问题