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# C# Basics Methods Return Values

Brandon Hunt
Brandon Hunt
329 Points

how do you return something

Program.cs
using System;

class Program
{

    static void Multiply(double firstParam, double secondParam)
    {
        Console.(firstParam * secondParam);
    }

    static int Main(string[] args)
    {
        Multiply(2.5, 2);
        Multiply(6, 7);
    }

}

2 Answers

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Treehouse Project Reviewer

Hey Brandon Hunt ! :wave:

As stated in the challenge, we'll want to return the results of the math in our Multiply method instead of logging it to the console. So we'll want to use the return keyword instead of Console.WriteLine().

Also, since this Multiply method will now be returning a value, we need to change void in the method to the data type we want to return, which is also stated in the challenge above.

Then you'll need to do similar changes for your second Main method. Just be sure to read the challenge tasks carefully :smiley: I hope this helps you out!

Steven Parker
Steven Parker
231,269 Points

There's a statement keyword just for this purpose, named return.

You might want to review the lesson on Method Return Values.