C# C# Basics (Retired) Prepare and Plan Program Structure

Arzija Racipovic
Arzija Racipovic
1,184 Points

i dont understand

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

2 Answers

Steven Parker
Steven Parker
177,891 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?

Arzija Racipovic
Arzija Racipovic
1,184 Points

i still dont understand it i need to visualize it

Steven Parker
Steven Parker
177,891 Points

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

Arzija Racipovic
Arzija Racipovic
1,184 Points

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
177,891 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.