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 (Retired) Prepare and Plan Program Structure

i dont understand

i dont understand the 4 parts of a method and what the () is for.

2 Answers

Steven Parker
Steven Parker
231,248 Points

Perhaps listing them out will help:

  • name — this just gives you a way to reference the method
  • body — this is where the code is that the method will run
  • parameters — the "input" the method will use (if any)
  • return value — the "output" from the method (if any)

And the parentheses () are put after the name to tell the the system you want the code in that method to run. If there are any parameters, they will be put between the parentheses.

Did that help?

i still dont understand it i need to visualize it

Steven Parker
Steven Parker
231,248 Points

I would think visuals would be a benefit of the video. Perhaps I'm not understanding what you need.

so

a program is a bunch of files that contain classes and the classes can contain methods wich is jut another word for functions.

Your first method should be always named Main so the program will know wich method to run first, because you can have a lot of methods.

the () is input and the left side of the methods "name" is where the output is going,

and the {} is the body. classes can have a body and a method can have body.

i know what void means but i would appreciate if you could explain it to me also what void means, so i can compare my understanding with yours. And also i dont know what static means in the method we use. i know that it is not the name, because the name is Main here.

i would appreciate it much if you could help.

Thanks.

Steven Parker
Steven Parker
231,248 Points

It sounds like you have a good understanding for the most part already!

And "void" simply means "this does not return anything". You'll notice that "void" functions and methods don't have any values in their "return" statements (or have no "return" statements at all).

Normally, a method can only be called using an instance of a class. But a "static" method is part of the class itself, so you call it using the class name instead, and do not need to have created an instance. So a static method is more like an ordinary function except that it has a fancy two-part name.