Learning C# through a book, and came upon these examples the author gave to convert a string value into an integer. These are:
myInt = Convert.ToInt32("123"
myString = Convert.ToString(123);
The problem is, the author didn't explain why & when I would choose to use one over the other and vice versa.
Also, the author states in another example: "Because you sometimes grab a numeric value from the console, you often simply put the Console.ReadLine() method inside the ToInt() parentheses, like this:"
myInt = Convert.ToInt32(Console.ReadLine());
Again, the author doesn't explain why or when you would do this. If I'm understanding this one (please correct me if I'm wrong) I'm reading in the user input, converting the string to an integer value type and then assigning that value to myInt?
If someone wouldn't mind explaining these to me and perhaps using these examples in a bit of code so that I could see the flow, I would greatly appreciate it. I appreciate your time and help.
myInt = Convert.ToInt32("123"
myString = Convert.ToString(123);
The problem is, the author didn't explain why & when I would choose to use one over the other and vice versa.
Also, the author states in another example: "Because you sometimes grab a numeric value from the console, you often simply put the Console.ReadLine() method inside the ToInt() parentheses, like this:"
myInt = Convert.ToInt32(Console.ReadLine());
Again, the author doesn't explain why or when you would do this. If I'm understanding this one (please correct me if I'm wrong) I'm reading in the user input, converting the string to an integer value type and then assigning that value to myInt?
If someone wouldn't mind explaining these to me and perhaps using these examples in a bit of code so that I could see the flow, I would greatly appreciate it. I appreciate your time and help.