DEV Community

Cover image for C# Basics - Methods
Grant Riordan
Grant Riordan

Posted on • Edited 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

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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay