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 Method Arguments

I don't understand this code from the method return values video.

I don't understand what this code means the video brings this up a lot and I just don't understand what it is and what he's doing with it... please help!!! .

static double Add(double first, double second) {

return first + second;

}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Tucker Kunkle! So we created an Add() function which adds two numbers. Simple enough. Now, we could choose to display the result right there, but what we're doing here is asking it to send us back the result from adding those. That's what return does. It ships us back something.

So here:

double total = Add(3, 5);

We're declaring a variable total of type double. We want the result to be whatever adding 3 and 5 is. So we issue a call to Add(). Many developers say "call the function", but you could also use the words execute/run/invoke. When we call it we send 3 and 5. The method returns 8. So now our total has a value of 8.

Then we use Console.WriteLine(total); to write out the value.

The key things to understand here are that during an assignment, whatever is on the right side of the equal sign happens first. So, in this case, we call/execute/run/invoke the Add() which sends back to us the result (8) which is then assigned to the variable total.

Hope this helps! :sparkles:

so cool! thank you Jennifer Nordell!!!