---
title: "difference between ref and out keywords"  
description: "difference between ref and out keywords"  
author: "Anupam Mishra"  
published: 2016-02-01  
updated: 2016-02-01  
canonical: https://www.mindstick.com/forum/33947/difference-between-ref-and-out-keywords  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 1 minute  

---

# difference between ref and out keywords

Hi Everyone, I want to know what is [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between [ref and out keywords](https://www.mindstick.com/interview/23293/difference-between-ref-and-out-keywords-in-c-sharp).Please can [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) give me a exact situation.thank you.

## Replies

### Reply by Anupam Mishra

\
If we want to pass a variable as **[ref](https://www.mindstick.com/interview/217/what-is-the-difference-between-ref-out-parameters) parameter** we need to initialize it before we pass it as ref parameter to method. Ref keyword will pass parameter as a reference this means when the value of parameter is changed in called method it get reflected in calling method also.\

```
i = 10;public static void RefTest(ref int val1){   val1 += 10;}Output : 20
```

If we want to pass a variable as **out parameter** we don’t need to initialize it before we pass it as out parameter to method. Out keyword also will pass parameter as a reference but here out parameter must be initialized in called method before it return value to calling method.\

```
int i,j; // No need to initialize variableOutTest(out i, out j);public static int OutTest(out int val1, out int val2){  val1 = 5;  val2 = 10;  return 0;}
```


---

Original Source: https://www.mindstick.com/forum/33947/difference-between-ref-and-out-keywords

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
