+ 2

ToString method

What is the difference between calling the ToString method for an int variable, lets say, in a WriteLine method and just using the variable.

31st Aug 2016, 9:02 AM
Ivelin Dinev
Ivelin Dinev - avatar
5 Respuestas
+ 5
ToString can convert a variable to string type, because WriteLine() needs a string value.
31st Aug 2016, 9:43 AM
LeParadoxHD | YouTube
LeParadoxHD | YouTube - avatar
+ 1
agree with paradoxh
1st Sep 2016, 2:09 PM
Shubham Priyesh
Shubham Priyesh - avatar
0
Thing is I can do it with a simple place holder or with the + sign.
31st Aug 2016, 4:49 PM
Ivelin Dinev
Ivelin Dinev - avatar
0
eg: int I= int.parse(Console.Readline());
27th Sep 2016, 4:18 PM
Tarun
0
guys the writeline() method accepts also the other variables. so if you write int a = 4; double d = 5.7; string str= "just testing"; Console.WriteLine( str + a + d); it compiles and the result is just testing45.7 with no space if you call the writeline method as follows: Console.WriteLine(str +" "+a+" "+d); you will get just testing 4 5.7 the Tostring method is used to convert an int double or whatever to string but it depends on your choise. for example the ToInt() method you can use it to convert the text input from user in int. ( the user input is always text not an int or double so you have to convert it to the type you need and also later you will learn the try and catch exception) 😉
29th Nov 2016, 8:47 AM
Taulant Qirjako
Taulant Qirjako - avatar