Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Methods 6:24
- Defining methods 4:14
- Methods 7 questions
- Variable Scope 3:17
- Defining a Method 1 objective
- Method Arguments 4:30
- Method Return Values 6:30
- The Difference Between Printing and Returning 1:42
- Variable Scope and Method Arguments 5 questions
- Returning a Value from the Ask Method 3:30
- Method Parameters 1 objective
- Return Values 5 questions
- Return Values 1 objective

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
If you declare a variable within a method, it's only accessible within that method. But trust us, that's a good thing!
- Variable declared within a method is accessible only within that method
- Can declare multiple variables with same name in different scopes
using System;
class Program
{
static void MyMethod()
{
// This "total" variable is completely
// separate from the "total" variable in
// the Main method!
int total = 0;
total += 1;
Console.WriteLine("total in MyMethod:");
Console.WriteLine(total);
}
static void Main(string[] args)
{
int total = 0;
total += 10;
MyMethod();
Console.WriteLine("total in Main:");
Console.WriteLine(total);
}
}
total in MyMethod:
1
total in Main:
10
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Jonathan Tucker
Ubora | Web Development Techdegree Student 16,987 Points0 Answers
-
Rajat Kadia
487 Points2 Answers
-
A X
12,842 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up