Monday , September 23 2019

C# 09 – Learning methods

C# methods

In this tutorial we will learn What are methods? and How to create a method in C# programming language?

Methods

Methods are a way of beautifying your coding style. It allows you to write code once, and use it again and again. It can reduce your 18 lines of execution code to only 12 lines, Wow! Re-usability and manageability is the key purpose of using methods.

Methods are usually verbs. For a student, checkAttendance() can be a method. For a calculator, add() can be a method.

Syntax of a C# method looks like this:

<access specifier> <return type> <method name>(<parameters>){
    <body of method>
}

// Example: An addition method that takes two inputs as parameters and returns output as decimal.

public decimal Add(int input1, int input2){
    
    return input1 + input2;

}

Methods are created where a piece of code is repeated again and again. Just like a variable in mathematics is used to replace a value.

Methods contain some instructions and algorithms to perform a task and whenever that method is invoked, called or used it will perform that function. So by just writing 1 or 2 line of code, you can repeat maybe 10 lines of code again and again i.e Re-usability of coded

Follow this tutorial in Urdu for learning about methods in C# programming language.

About Waleed Baig

Waleed Baig
I am doing BS Computer Science. I have a passion to learn new technology and spread it. I am more enthusiastic about learning complex algorithm and making creative and efficient solution to a problem.

Check Also

C# – More on arrays, loops and conditionals (Part 2)

  This is the 2nd part of: More about arrays, loops and conditionals (Part 1) Part 2: …

2 comments

  1. Waleed Baig

    OK I will make very soon

  2. Avatar

    plz make tutorial in C# about enum

Leave a Reply

Your email address will not be published.