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 Defining methods

Need Help Simplifying What a Method Is

I've been scratching my head recently, trying to understand methods. I have reviewed the videos "Methods" and "Defining Methods," and still don't know what a method is. I did the entire C# Basic section, until the method coding challenge, only realizing I don't understand the concept of it.

Is the entire line: static string Ask(string question) a method?

Or is the entire line: Console.ReadLine(); a method?

Or is: .ReadLine(); without Console. a method?

I feel discouraged in my ability to grasp something that may be so simple, and I feel silly asking. Thanks for your help.

1 Answer

// Methods are functions within a class

// *** This is a method
static string Ask(stringQuestion)
{
    // static string Ask(stringQuetion) is declaring a method that will return a string
   return stringQuestion;
}
// ** This is a method

// In a program it would look like ...
public class SomeClass
{
    static string Ask(stringQuestion)
    {
        // static string Ask(stringQuetion) is declaring a method that will return a string
       return stringQuestion;
     }
}

// It would be called by
SomeClass.Ask();

// In the Console.readline() Console is the class and Readline() the method. 
// this command is saying call Readline() from the class Console
Console.Readline();

A method is a block of code within a class that does something specific. If the class was for building a list, methods might... sort the list, add to the list, delete from the list.. etc...