12
C# Basics - Methods
So now we've learnt about variables, classes, and the public and private accessors, the next thing to learn is Methods
Methods are hugely important to OOP (Obect Orientated Programming), and allow developers to apply logic to the classes properties and fields. Without them we would have no code / functionality.
Methods can range in size from 1 line of code (statement) or multiple lines of code.
They consist of these parts:
Part | Description |
---|---|
Accessor | Determines the visibility of method to other methods or classes. |
Return Type | Determines what type of object is returned from the method (e.g boolean, string, int) |
Name | The name of the method, method named are always written in Pascal Case |
Parameter List | Used to pass information from other classes or methods to utilise within the method. These are optional |
Body | The body of the method, the actual logic statements. |
Lets take a look.
![](https://res.cloudinary.com/practicaldev/image/fetch/s--dsKIuyJQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7ynyo10hqfzgb7c65vd.png)
now lets disect this:
![](https://res.cloudinary.com/practicaldev/image/fetch/s--fXZk_44N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gm8jgkxodhkv20o0tci7.png)
This is the basics of methods, we will look them into more detail in future tutorials.
Next up --> Building your first Console Application, the classic "Hello World";
12