DEV Community

Cover image for C# Basics - Methods

Posted on

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.

Alt Text

now lets disect this:

Alt Text

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";

Discussion (0)