---
title: "What is the difference between ref & out parameters."  
description: "What is the difference between ref & out parameters."  
author: "Anonymous User"  
published: 2015-11-15  
updated: 2015-11-15  
canonical: https://www.mindstick.com/forum/33592/what-is-the-difference-between-ref-out-parameters  
category: ".net"  
tags: ["c#"]  
reading_time: 1 minute  

---

# What is the difference between ref & out parameters.

i want know [difference between ref](https://www.mindstick.com/forum/253/difference-between-ref-and-out-keyword-in-c-sharp) &[amp](https://www.mindstick.com/forum/156207/what-is-amp); out [parameters](https://www.mindstick.com/articles/87/passing-parameters-in-c-sharp) [please explain](https://www.mindstick.com/forum/344/hi-rohith-i-am-new-for-mvc-please-explain-how-to-set-implicitly-isauthenticated-true) it.

## Replies

### Reply by Anonymous User

The [ref](https://www.mindstick.com/interview/217/what-is-the-difference-between-ref-out-parameters) keyword is used to pass an argument as a reference. This means that when value of that parameter is changed in the method, it gets reflected in the calling method. An argument that is passed using a ref keyword must be initialized in the calling method before it is passed to the called method.

The out keyword is also used to pass an argument like ref keyword, but the argument can be passed without assigning any value to it. An argument that is passed using an out keyword must be initialized in the called method before it returns back to calling method.

```
using System;using System.Collections.Generic;using System.Diagnostics;using System.Linq;using System.Net;using System.Text;using System.Threading;namespace Forum{
    public class RefAndOut     {        static void Main(string[] args)        {           int refval = 0; //must be initialized           int outval; //optional          RefExample(ref refval);        Console.WriteLine(refval); // refval=1         OutExample(out outval);         Console.WriteLine(outval); // outval=2         Console.ReadLine();
         }         static void RefExample(ref int value) //called method         {         value = 1;         }         static void OutExample(out int value) //called method         {         value = 2; //must be initialized          }         }
    }
```


---

Original Source: https://www.mindstick.com/forum/33592/what-is-the-difference-between-ref-out-parameters

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
