Locked lesson.
About this lesson
If you'd like to use Methods and return data to your program, we explore how that's done.
Exercise files
Download this lesson’s related exercise files.
29 - Return Methods.docx61.5 KB 29 - Return Methods SOLUTION.docx
58.5 KB
Quick reference
Return Methods
Methods can return data back to your main program.
When to use
Do this whenever you want to return data back to your program from a method.
Instructions
{
int a, b
a = 3;
b = 2;
Addthings(a,b);
result = Addthings(a, b);
Console.WriteLine($"{a} + {b} = {result}");
}
static int Addthings(int x, int y)
{
return x + y;
}
Hints & tips
- Remember to call a method as the data type to be returned, if you plan on returning data from that method.
Lesson notes are only available for subscribers.