Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Tirth Upadhyay920 Points
why not int instead of string?
we use : string Input = Console.ReadLine();
then we need to convert the string into integer.
why cant we directly use the integer????
Jennifer NordellTreehouse Teacher
Because everything coming in from the user from the console is a string. So we have to take what they have put in and change it to an integer. This is not specific to C#. All input from the user (in most languages I know) have what's coming in as strings.
edited for additional note
While you could try to parse the integer from their input when originally assigning to the variable, any incorrect input from the user would cause an unhandled exception and your program would crash. This (imo) would not be the best solution.
Gi Devs12,171 Points
we could in theory do it all in one line but for starting perposes it is better to split it up. I like to experiment a bit and work thing s out on my own and I came up with this
int newInput = System.Int32.Parse(System.Console.ReadLine());