Methods in C#

This article explains Methods in C# using various analogies. Why analogies? I learn faster that way and I’m sure it’s the same for a lot of other folks.

What is a method?

A method is a code block that contains a series of statements [1] . Statements as well, are executed by a program.
You can liken a method to a box of matches which contains multiple match sticks and statements are executed just like you would ignite a match stick with the striking surface on the match box.

Photo by Gary Ellis on Unsplash

The program ,which executes the method, calls the method first of all and specifies all the required method arguments.

I apply my mind to the process of lightening the match box and lift the match box from the surface and determines if it will work and how much effort/force needs to be applied by the human (me) and the stick.

In C#, every executed instruction is performed in the context of a method. The lightning of the match stick happens in relation to the match box

The Main method is the entry point for every C# application and it’s called by the common language runtime (CLR) when the program is started.

main method like a type of match box.

Method Signature

Methods are declared in a class, struct, or interface. The method is declared (signature) by doing the following.
By specifying :

a. the access level/access modifiers which can be either public, private, protected, internal, protected internal or private protected [2] .

Public, which is underlined in white is the specified access level.

b. return value

d. name of the method

e. any method parameters

I hope you learnt a couple of things from this article. Totally open to corrections and discusions. Please Give me a clap if you found it useful! Do have a great day.

Leave a comment