Advertisement
_DeNiS_On4Ik_

Exam2.1

Jun 28th, 2022
809
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int arg;
  6.  
  7.         // Passing by value.
  8.         // The value of arg in Main is not changed.
  9.         arg = 4;
  10.         squareVal(arg);
  11.         Console.WriteLine(arg);
  12.         // Output: 4
  13.  
  14.         // Passing by reference.
  15.         // The value of arg in Main is changed.
  16.         arg = 4;
  17.         squareRef(ref arg);
  18.         Console.WriteLine(arg);
  19.         // Output: 16
  20.     }
  21.  
  22.     static void squareVal(int valParameter)
  23.     {
  24.         valParameter *= valParameter;
  25.     }
  26.  
  27.     // Passing by reference
  28.     static void squareRef(ref int refParameter)
  29.     {
  30.         refParameter *= refParameter;
  31.     }
  32. }
Advertisement
RAW Paste Data Copied
Advertisement