Login Register
Code2night
  • Home
  • Guest Posts
  • Blog Archive
  • Tutorial
  • Languages
    • Angular
    • C
    • c#
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • Security
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
    • Word Counter
    • Base64 Encode/Decode
    • Diff Checker
    • JSON to CSV
    • Password Generator
    • SEO Analyzer
  1. Home
  2. Blog
  3. Call By Reference

Call By Reference

Date- Dec 09,2023

3123

Call By Reference

On passing variables in a function, any changes made in the passed parameter will update the original variable’s reference too. To pass an argument as reference-type instead of the copy of the original value, i.e, to pass a reference of arguments to the function the ref keyword is used in C#.

Features of call by reference

  • Changes in one object variable affect the other object variable.
  • Actual and copied variables are created in the same memory location.


using System;  
namespace MyApplication
{  
    class Test  
    {  
        public void Display(ref int x)  
        {  
             x += x;  
            Console.WriteLine("Value inside the function: "+ x);  
        }  
        static void Main(string[] args)  
        {  
            int x = 200;  
            Test abc = new Test(); 
            Console.WriteLine("Value before calling: "+ x);  
            abc.Display(ref x);            
            Console.WriteLine("Value after calling: " + x);  
        }  
    }  
}


OUTPUT

Value before calling: 200
Value inside the function: 400
Value after calling: 400

S
Shubham Saini
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Zoom C# Wrapper Integration
Jun 12, 2021
Convert HTML String To Image In C#
Jul 02, 2022
The report definition is not valid or is not supported by this version of reporting
Jul 02, 2022
Replacing Accent Characters with Alphabet Characters in CSharp
Jun 03, 2023

Comments

Contents

More in C#

  • Get IP address using c# 8595 views
  • How to Convert DataTable to List 7616 views
  • Asynchronous Programming in C# 7558 views
  • How to Verify If base 64 string is valid for tiff image in C… 7108 views
  • Compress image using ImageCompress NuGet package 6930 views
View all C# posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Free Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Diff Checker
  • Base64 Encode/Decode
  • Word Counter
  • SEO Analyzer
By Language
  • Angular
  • C
  • c#
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page