Passing ref-types by value : Parameter Value : Language Basics C# Examples


C# Examples » Language Basics » Parameter Value »

 

Passing ref-types by value









    
using  System;

class  Person
{
    public  string  fullName;
    public  int  age;

    public  Person(string  n,  int  a)
    {
        fullName  =  n;
        age  =  a;
    }

    public  void  PrintInfo()
    {
        Console.WriteLine("{0}  is  {1}  years  old",  fullName,  age);
    }
}

class  MainClass
{
    public  static  void  SendAPersonByValue(Person  p)
    {
        p.age  =  99;

        p  =  new  Person("TOM",  999);
    }

    public  static  void  Main()  
    {
        Person  fred  =  new  Person("Fred",  12);
        fred.PrintInfo();
        SendAPersonByValue(fred);
        fred.PrintInfo();
    }
}
    
   
  
   



Output

Fred is 12 years old
Fred is 99 years old


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Parameter Value