Understanding and writing his first method in C #

As we are developing our code, we realize that they can be divided according to their functionality. By carrying out this division, we are actually creating blocks of code that perform a certain task. And we found that these code blocks can be reused often in the same program. Thus, the mechanism used to trigger the execution of code blocks is given the name of the method (or function in languages ​​such as C and C + +).

A method in its simplest form, is just a set of instructions that can be called from a program of strategic locations. Here’s an example:
/ / A method that takes no arguments
/ / And returns no value
static void method () {
Console.WriteLine (“I am a method”);
}
This method only displays the text “I’m a method.” See the use of braces {and} to delimit the area of ​​operation of the method (the method body). The keyword void indicates that this method returns no value at the end of its execution while the static keyword is best explained in our section on modifiers in C #. All methods in C # have brackets, which serve as markers for the list of method parameters. Empty parentheses indicate that the method has no parameters.

Listen now to a full code snippet illustrating the call to the newly created:
/ / A method that takes no arguments
/ / And returns no value
static void method () {
Console.WriteLine (“I am a method”);
}

static void Main (string [] args) {
/ / Make a call to the method
method ();

Console.WriteLine (“\ n \ nPress a key to exit …”);
Console.ReadKey ();
}

 

Let’s go training 🙂

 

Font: http://www.arquivodecodigos.net/dicas/c-csharp-entendendo-e-escrevendo-seu-primeiro-metodo-em-c-2515.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.