Ref, Out & In - C#
📰 Dev.to · Mirza Leka
Learn how to use ref, out, and in keywords in C# to pass arguments by reference
Action Steps
- Use the ref keyword to pass variables by reference, allowing the method to modify the original variable
- Apply the out keyword to pass variables by reference, requiring the method to assign a value to the variable before returning
- Utilize the in keyword to pass variables by reference, allowing the method to read but not modify the original variable
- Create a method that takes a ref parameter and modifies its value
- Invoke the method and verify that the original variable has been modified
Who Needs to Know This
Software engineers and developers working with C# can benefit from understanding how to use ref, out, and in keywords to pass arguments by reference, improving code efficiency and effectiveness.
Key Insight
💡 The ref, out, and in keywords in C# allow for passing arguments by reference, enabling methods to modify original variables or require assignment of values.
Share This
💡 Use ref, out, and in keywords in C# to pass args by reference!
Key Takeaways
Learn how to use ref, out, and in keywords in C# to pass arguments by reference
Full Article
Title: Ref, Out & In - C#
URL Source: https://dev.to/mirzaleka/ref-out-in-c-cin
Published Time: 2026-06-20T11:08:18Z
Markdown Content:
# Ref, Out & In - C# - DEV Community
[Skip to content](https://dev.to/mirzaleka/ref-out-in-c-cin#main-content)
[](https://dev.to/)
[Powered by Algolia](https://www.algolia.com/developers/?utm_source=devto&utm_medium=referral)
[Log in](https://dev.to/enter?signup_subforem=1)[Create account](https://dev.to/enter?signup_subforem=1&state=new-user)
## DEV Community
0 Add reaction
0 Like 0 Unicorn 0 Exploding Head 0 Raised Hands 0 Fire
0 Jump to Comments 0 Save Boost
Copy link
Copied to Clipboard
[Share to X](https://twitter.com/intent/tweet?text=%22Ref%2C%20Out%20%26%20In%20-%20C%23%22%20by%20%40mirzaleka%20%23DEVCommunity%20https%3A%2F%2Fdev.to%2Fmirzaleka%2Fref-out-in-c-cin)[Share to LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fdev.to%2Fmirzaleka%2Fref-out-in-c-cin&title=Ref%2C%20Out%20%26%20In%20-%20C%23&summary=In%20C%23%2C%20ref%2C%20out%2C%20and%20in%20are%20keywords%20used%20to%20pass%20arguments%20to%20methods%20by%20reference%20rather%20than%20by...&source=DEV%20Community)[Share to Facebook](https://www.facebook.com/sharer.php?u=https%3A%2F%2Fdev.to%2Fmirzaleka%2Fref-out-in-c-cin)[Share to Mastodon](https://s2f.kytta.dev/?text=https%3A%2F%2Fdev.to%2Fmirzaleka%2Fref-out-in-c-cin)
[Share Post via...](https://dev.to/mirzaleka/ref-out-in-c-cin#)[Report Abuse](https://dev.to/report-abuse)
[](https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8edab32w6d0pvh2jgz6n.png)
[](https://dev.to/mirzaleka)
[Mirza Leka](https://dev.to/mirzaleka)
Posted on Jun 20
# Ref, Out & In - C#
[#csharp](https://dev.to/t/csharp)[#dotnet](https://dev.to/t/dotnet)[#programming](https://dev.to/t/programming)
In C#, `ref`, `out`, and `in` are keywords used to pass arguments to methods by reference rather than by value.
## [](https://dev.to/mirzaleka/ref-out-in-c-cin#passing-variables-by-reference) Passing variables by reference
Consider this. We want to modify a local variable in the `SetFullName()` method:
```
private static void SetFullName(string nameToSet)
{
nameToSet = "Mirza Leka";
}
```
But the `SetFullName()` method does not return the modified name. Thus, when we invoke the method from the outside, the calling method still has the old name.
```
internal class Program
{
static void Main(string[] args)
{
var na
URL Source: https://dev.to/mirzaleka/ref-out-in-c-cin
Published Time: 2026-06-20T11:08:18Z
Markdown Content:
# Ref, Out & In - C# - DEV Community
[Skip to content](https://dev.to/mirzaleka/ref-out-in-c-cin#main-content)
[](https://dev.to/)
[Powered by Algolia](https://www.algolia.com/developers/?utm_source=devto&utm_medium=referral)
[Log in](https://dev.to/enter?signup_subforem=1)[Create account](https://dev.to/enter?signup_subforem=1&state=new-user)
## DEV Community
0 Add reaction
0 Like 0 Unicorn 0 Exploding Head 0 Raised Hands 0 Fire
0 Jump to Comments 0 Save Boost
Copy link
Copied to Clipboard
[Share to X](https://twitter.com/intent/tweet?text=%22Ref%2C%20Out%20%26%20In%20-%20C%23%22%20by%20%40mirzaleka%20%23DEVCommunity%20https%3A%2F%2Fdev.to%2Fmirzaleka%2Fref-out-in-c-cin)[Share to LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fdev.to%2Fmirzaleka%2Fref-out-in-c-cin&title=Ref%2C%20Out%20%26%20In%20-%20C%23&summary=In%20C%23%2C%20ref%2C%20out%2C%20and%20in%20are%20keywords%20used%20to%20pass%20arguments%20to%20methods%20by%20reference%20rather%20than%20by...&source=DEV%20Community)[Share to Facebook](https://www.facebook.com/sharer.php?u=https%3A%2F%2Fdev.to%2Fmirzaleka%2Fref-out-in-c-cin)[Share to Mastodon](https://s2f.kytta.dev/?text=https%3A%2F%2Fdev.to%2Fmirzaleka%2Fref-out-in-c-cin)
[Share Post via...](https://dev.to/mirzaleka/ref-out-in-c-cin#)[Report Abuse](https://dev.to/report-abuse)
[](https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8edab32w6d0pvh2jgz6n.png)
[](https://dev.to/mirzaleka)
[Mirza Leka](https://dev.to/mirzaleka)
Posted on Jun 20
# Ref, Out & In - C#
[#csharp](https://dev.to/t/csharp)[#dotnet](https://dev.to/t/dotnet)[#programming](https://dev.to/t/programming)
In C#, `ref`, `out`, and `in` are keywords used to pass arguments to methods by reference rather than by value.
## [](https://dev.to/mirzaleka/ref-out-in-c-cin#passing-variables-by-reference) Passing variables by reference
Consider this. We want to modify a local variable in the `SetFullName()` method:
```
private static void SetFullName(string nameToSet)
{
nameToSet = "Mirza Leka";
}
```
But the `SetFullName()` method does not return the modified name. Thus, when we invoke the method from the outside, the calling method still has the old name.
```
internal class Program
{
static void Main(string[] args)
{
var na
DeepCamp AI