---
title: "Out parameter in c#"  
description: "Out parameter in c#"  
author: "Madam Walker"  
published: 2013-09-28  
updated: 2013-09-28  
canonical: https://www.mindstick.com/forum/1572/out-parameter-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Out parameter in c#

I am new to C#. I've tried this with out [parameter in C#](https://www.mindstick.com/forum/34334/use-of-out-parameter-in-c-sharp)

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class First
{
    public void fun(out int m)
    {
        m *= 10;
        Console.WriteLine("value of m = " + m);
    }
}
class Program
{
    static void Main(string[] args)
    {
        First f = new First();
        int x = 30;
        f.fun(out x);
    }
}
```

\
but i get some [errors](https://answers.mindstick.com/qa/116170/fresh-fir-against-gandhis-in-national-herald-case-cover-up-for-ed-s-own-errors) like "Use of unassigned out parameter 'm'" and

The out parameter 'm' [must](https://www.mindstick.com/articles/12978/top-reasons-why-every-magento-ecommerce-store-must-opt-for-mobile-app) be assigned to before [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) leaves the current method.

So what is the meaning of these errors and why it is compulsory to assign 'm' when i'm [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) assigned a [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) to x.

## Replies

### Reply by Anonymous User

Hello Madam!

```
public void Ref_Test(ref int x)
{
    var y = x; // ok
    x = 10;
}
// x is treated as an unitialized variable
public void Out_Test(out int x)
{
    var y = x; // not ok (will not compile)
}
public void Out_Test2(out int x)
{
    x = 10;
    var y = x; // ok because x is initialized in the line above
}Hello Madam!
public void Ref_Test(ref int x)
{
    var y = x; // ok
    x = 10;
}
// x is treated as an unitialized variable
public void Out_Test(out int x)
{
    var y = x; // not ok (will not compile)
}
public void Out_Test2(out int x)
{
    x = 10;
    var y = x; // ok because x is initialized in the line above
}
```


---

Original Source: https://www.mindstick.com/forum/1572/out-parameter-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
