---
title: "What is the ‘ref’ and ‘out’ parameter?"  
description: "What is the ‘ref’ and ‘out’ parameter?"  
author: "Om ji mishra"  
published: 2019-10-23  
updated: 2019-10-23  
canonical: https://www.mindstick.com/forum/135437/what-is-the-ref-and-out-parameter  
category: "c#"  
tags: ["c#", "programming language"]  
reading_time: 2 minutes  

---

# What is the ‘ref’ and ‘out’ parameter?

What is the ‘[ref](https://www.mindstick.com/interview/217/what-is-the-difference-between-ref-out-parameters)’ and ‘out’ [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp)? \

## Replies

### Reply by Om ji mishra

REF: - In the ref parameter, we pass the parameter by using ‘ref’ keyword. When we pass any ref parameter then we have to assign value in that variable those we have to pass. Without assigning we cannot pass the parameter.

Syntax: - method name(ref value type variable name);

OUT: - In the out parameter, we pass the parameter by using ‘out’ keyword. When we pass any out parameter then we don’t have assign value in that variable those we have to pass.

Syntax: - method name(out value type variable name);

Example: -"OUT"

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BreakAndContinue
{
    class Program
    {
         public static void Add(out int a)
        {
            a = 50;
            Console.WriteLine(a);
        }

        static void Main(string[] args)
        {
            int b;
            Add(out b);
            Console.ReadKey();
        }

         }
    }
```

Example: -"ref"

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BreakAndContinue
{
    class Program
    {
         public static void Add(ref int a)
        {
            a = 50;
            Console.WriteLine(a);
        }

        static void Main(string[] args)
        {
            int b=1;
            Add(ref b);
            Console.ReadKey();
        }

         }
    }
```


---

Original Source: https://www.mindstick.com/forum/135437/what-is-the-ref-and-out-parameter

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
