You can use the keyword ref in csharp to pass a value by reference instead of call by value .
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Namespace1 { class Student { public string StudentName { get; set; } /* usage of the pass by reference using the keyword ref */ public void Add(ref int i) { i = i + i; } } class Program { public static void Main() { Student studentObj = new Student(); int i = 10; Console.WriteLine("i = : " + i); studentObj.Add(ref i); Console.WriteLine("i: " + i); } } }
Leave a Reply