Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Method Parameters | Methods
C# Basics

Method ParametersMethod Parameters

Sometimes we need to pass some data into the methods so it can process that data and give us some output. For example, we can create a method that calculates the sum of three numbers and outputs the result. Such a thing can be achieved using method parameters.

We can create a method with parameters using the following syntax:

cs

main.cs

For-example:

cs

main.cs

Note

It's also possible to write expressions directly in string formatting, therefore writing Console.WriteLine($"The sum is {a + b + c}") is also valid in the above case.

In the above code the terms a, b, and c represent the passed data. When we are calling such a method we pass the data along with it. The syntax for executing/calling such a method is the following:

cs

main.cs

For-example:

cs

main.cs

Note

An argument is a value that you pass to a method when calling it, for example 1, 2, and 3 in the above example are arguments. On the other hand, a parameter is a variable declared in the method's definition to receive and work with those arguments. In the above case a, b, and c are the parameters.

Here is the full code for the above example:

cs

main.cs

The following illustration explains the flow:

When calling a method, we must always provide the required amount of arguments, otherwise, the code might not compile:

cs

main.cs

Apart from that, the order of the arguments must also match the definition of the method. For-example:

cs

main.cs

What is a valid way to call the following method?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 6. Розділ 4
course content

Зміст курсу

C# Basics

Method ParametersMethod Parameters

Sometimes we need to pass some data into the methods so it can process that data and give us some output. For example, we can create a method that calculates the sum of three numbers and outputs the result. Such a thing can be achieved using method parameters.

We can create a method with parameters using the following syntax:

cs

main.cs

For-example:

cs

main.cs

Note

It's also possible to write expressions directly in string formatting, therefore writing Console.WriteLine($"The sum is {a + b + c}") is also valid in the above case.

In the above code the terms a, b, and c represent the passed data. When we are calling such a method we pass the data along with it. The syntax for executing/calling such a method is the following:

cs

main.cs

For-example:

cs

main.cs

Note

An argument is a value that you pass to a method when calling it, for example 1, 2, and 3 in the above example are arguments. On the other hand, a parameter is a variable declared in the method's definition to receive and work with those arguments. In the above case a, b, and c are the parameters.

Here is the full code for the above example:

cs

main.cs

The following illustration explains the flow:

When calling a method, we must always provide the required amount of arguments, otherwise, the code might not compile:

cs

main.cs

Apart from that, the order of the arguments must also match the definition of the method. For-example:

cs

main.cs

What is a valid way to call the following method?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 6. Розділ 4
some-alt