Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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());