C# Out Parameter

Last Updated : 27 Jun 2026

C# provides special parameter types that allow methods to return additional information to the caller. One of these is the out parameter, which is used to pass values by reference.

In this chapter, you will learn what an out parameter is, its syntax, how it works, and how to use it in C# with examples.

What is a C# Out Parameter?

The out parameter is used to pass an argument by reference and return a value from a method. Unlike a normal variable, an out parameter does not need to be initialized before it is passed to the method. However, the called method must assign a value to the out parameter before it returns.

The out keyword is commonly used when a method needs to return multiple values.

Syntax

It has the following syntax:

Parameters

  • void: It is the void type method, which means the method does not return a value directly.
  • DataType: It defines the type of data that has been passed to the method.
  • Parameter: It is used for holding the value that has been passed to the variable.

C# Out Parameter Example

Let us take an example to illustrate the out parameter in C#.

Compile and Run

Output:

The Square of 6 is: 36

Explanation:

In this example, we have taken the out parameter to calculate the square of a number. After that, we define a method named GetSquare that takes an integer input and uses an out parameter to return its square. In the main method, we define the number and call the GetSquare method. Finally, we print the square of a number using Console.WriteLine() function.

Important Points of Out parameter

Several important points of out parameter in C# are as follows:

  • It is similar to the ref keyword.
  • The data is passed in a unidirectional (out) manner.
  • Method overloading can also be done using an out parameter.
  • We cannot use properties as an out parameter because they are not actual variables that can be changed directly.

Example: Passing an Out Parameter to a Method

Let us take an example to illustrate an out parameter in C#.

Compile and Run

Output:

The Value set by the method: 10

Explanation:

In this example, we create a method named SetValue that accepts one out parameter called number. Inside the method, we assign the value 10 to this parameter. In the Main method, we declare a variable result without initializing it. After that, we create an object of the program class and call the SetValue method using the out keyword. This allows the method to set the value of the result.

When to use an out parameter in C#?

In C# programming, the out parameter is used when we need to return more than one value from the method. Let's take an example of two numbers from a single method call.

Example

Compile and Run

Output:

Sum: 15, Product: 50

Explanation:

In this example, we create a method named SumAndProduct that accepts two out parameters. Inside this method, we calculate the sum and product of the numbers. In the main method, we declare that the (5 and 10) values are passed to the method and return their sum and product of the number.

C# Multiple Out Parameters

In C#, the multiple out parameter allows passing multiple out parameters to the method, and the method returns multiple values.

Syntax

It has the following syntax.

In this syntax,

  • return_type: It specifies the type of method.
  • datatype: It defines the type of data that has been passed to the method.

Let us take an example to illustrate the multiple parameters in C#.

Example

Compile and Run

Output:

Name: Alice
Age: 25
City: New York

Explanation:

In this example, we create a method named PrintDetails that accepts three parameters: a name, an age, and a city. Next, we use the Console.WriteLine() function to print these values. After that, we have call the methods(PrintDetails) in the main method by passing the values "Alice", 25, and "New York".

Difference between ref and out keyword

Several differences between the ref and out keywords are as follows:

refout
It is mandatory to initialize the parameter before it is passed to the ref.It is not necessary to initialize the parameter before it is passed to out.
It does not need to initialize the value of the parameter.It is necessary to initialize the value of the parameter.
The data is passed in a bi-directional(in/out).The data is passed in unidirectional(out).
It is used for modifying the existing value.It is used for returning a new value.

Next TopicC# Arrays