+ 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.
5 Answers
+ 5
ToString can convert a variable to string type, because WriteLine() needs a string value.
+ 1
agree with paradoxh
0
Thing is I can do it with a simple place holder or with the + sign.
0
eg: int I= int.parse(Console.Readline());
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) đ