Value types are passed by value : Parameter Value : Language Basics C# Examples


C# Examples » Language Basics » Parameter Value »

 

Value types are passed by value









    
using  System;  
  
class  Test  {  
    /*  This  method  causes  no  change  to  the  arguments  used  in  the  call.  */  
    public  void  noChange(int  i,  int  j)  {  
        i  =  i  +  j;  
        j  =  -j;  
    }  
}  
  
class  MainClass  {  
    public  static  void  Main()  {  
        Test  ob  =  new  Test();  
  
        int  a  =  15,  b  =  20;  
  
        Console.WriteLine("a  and  b  before  call:  "  +  
                                              a  +  "  "  +  b);  
  
        ob.noChange(a,  b);    
  
        Console.WriteLine("a  and  b  after  call:  "  +  
                                              a  +  "  "  +  b);  
    }  
}
    
   
  
   



Output

a and b before call: 15 20
a and b after call: 15 20


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Parameter Value