Skip to main content

C # Tutorial, Methods

 Hello, Welcome to C# Tutorial. My name is Abdul Yesdani. Today we are going to learn about methods in C# programing language.

Method is a bunch of code or statements which perform a single task. Here you can see the method example.

    static void Hello(string name)

        {

            Console.WriteLine("Hello!" + name +"  Welcome to C#");

            Console.WriteLine("Methods can have n number of statements");

            Console.WriteLine("method will perform a single task");

        }

Methods can have parameters as shown in the above example, 'string name' is a parameter must be passed its value at the calling method in side the Main() method.




Press Ctrl+ F5 to run the application. You will get the following output.



In the above example you can see 'void'  keyword before method name. Means method return type is void , i.e., method returns nothing. We can return any type through a method, It can be an int type, double type, string type or any other type.

The following example is showing  Add2Numbers(int no1, int no2)  method which is returning a value.


Run the application by pressing Ctrl + F5 keys. You will get the following output.


Methods are basic building blocks in side a class in any application .

*Please help us to improve the tutorial by commenting in the comment section. 


Comments

Popular posts from this blog

.Net Presentation

.NET is a free, cross-platform, open source developer platform for building many different types of applications. With .NET, you can use multiple languages, editors, and libraries to build for web, mobile, desktop, games, and IoT. You can write .NET apps in C#, F#, or Visual Basic. C# is a simple, modern, object-oriented, and type-safe programming language. F# is a programming language that makes it easy to write succinct, robust, and performant code. Visual Basic is an approachable language with a simple syntax for building type-safe, object-oriented apps. You can write .NET apps in C#, F#, or Visual Basic. C# is a simple, modern, object-oriented, and type-safe programming language. F# is a programming language that makes it easy to write succinct, robust, and performant code. Visual Basic is an approachable language with a simple syntax for building type-safe, object-oriented apps.

Bootstrap

  Bootstrap is a powerful, feature-packed frontend toolkit. Build anything—from prototype to production. Bootstrap includes HTML and CSS based design templates for typography, forms, buttons, tables, navigation, modals, image carousels and many other, as well as optional JavaScript plugins Bootstrap also gives you the ability to easily create responsive designs. Get started by including Bootstrap’s production-ready CSS and JavaScript via CDN without the need for any build steps.