I just started the CodeCademy C# course this evening and have a question. I am in the converting data type section and was able to "pass" the exercise but the code did not output what I expected. When I run the program it prompts "Whats your favorite number?" if I input 5 it does what I expected and outputs "your favorite number is 5". What I don't understand is if I input five
, the program throws an incorrect format error
. I thought the Convert.ToInt32() method was supposed to take a string input and convert it to its corresponding integer? Any help understanding what I am doing or thinking wrong is appreciated.
static void Main(string[] args) {
// Ask user for fave number
Console.Write("Enter your favorite number?: ");
// Turn that answer into an integer
int faveNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("your favorite number is:" + faveNumber);
}