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

C#

Why does the type of the return value doesn't have to match with parameter values?

I can use int for this method while the parameters are double why is that?

static int Add (double first, double second)
    {

    }

1 Answer

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello, Kevin

The return type of a function does not depend on its parameters because they don't dictate what will be returned by the function.

For example, say you want to create a function that will take a string as an argument, and you want to return the number of words found in the string. In that example, the function would have a parameter of type string and a return type of integer.

I hope this helps. Happy coding.