Answer: Yes, you can pass value types by reference to a method. Below is one sample code snippet to have clear idea.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sample
{
class Program
{
public static void Main()
{
int a = 10;
Console.WriteLine("Value of a before passing to the method = " + a);
Function(ref a);
Console.WriteLine("Value of a after passing to the method by reference= " + a);
}
public static void Function(ref int Num)
{
Num = Num + 5;
}
}
}
Asked In: Many Interviews |
Alert Moderator