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 trialbenovarghese
2,059 Pointschange method return type
In this video, you use Parse to convert the string that is returned from the method, to an Int. Can we also change the return type of the method itself to Int so that it returns an int instead of string? in order to avoid using Parse. Are there instances where you will require the value to be one type (ex: string) but need to use it as a different type (ex: int) in another part of the code?
1 Answer
Steven Parker
231,248 PointsYou could certainly create a method like "Ask" that returns a number instead of a string, but the int.Parse would need to be done there to convert the input string to the proper return type. So you wouldn't avoid using Parse, but then, why would you want to? It's exactly what's needed there.
And yes, conversion between types is a common part of many programs.
benovarghese
2,059 Pointsbenovarghese
2,059 PointsThanks!