Pass by Value by default

By default , the Value type (Data types) are pass by value . Below is a sample sourcecode that demonstrates the pass by value .

class Student
{
        public string StudentName { get; set; }
        /* Demo of Pass by Value  */
        public void Add( int i)
        {
            i = 0;
            i = i + i;
        } 
}
class Program
{
        public static void Main()
        {
            Student studentObj = new Student();
            Console.WriteLine("i = : " + i);
            int i = 10;
            studentObj.Add(i);
            Console.WriteLine("i: " + i);
        }
}
%d bloggers like this: