Can you pass value types by reference to a method?

 Posted by Tripati_tutu on 11/16/2010 | Category: C# Interview questions | Views: 2945 | Points: 40

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 

Comments or Responses

Login to post response