Answers for "passing by reference c#"

C#
9

c# ref

void Method(ref int refArgument)
{
    refArgument = refArgument + 44;
}

int number = 1;
Method(ref number);
Console.WriteLine(number);
// Output: 45
Posted by: Guest on May-20-2020
2

c# pass value by reference

using System;

namespace ProgramName
{
     class Program
     {
         static void Main(string[] args)
         {
             int x = 10;
             Console.WriteLine("Variable Value Before Calling the Method: {0}", x);//10
             Square(ref x);
             Console.WriteLine("Variable Value After Calling the Method: {0}", x);//100
         }
         public static void Square(ref int a)
         {
              a *= a;
              Console.WriteLine("Variable Value Inside the Method: {0}", a);//100
         }
     }
}
Posted by: Guest on June-25-2021

C# Answers by Framework

Browse Popular Code Answers by Language