connor12568

Untitled

Dec 2nd, 2021 (edited)
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using static System.Console;
  3.  
  4.  
  5. namespace Ref_Example
  6. {
  7.     class Program
  8.     {
  9.        
  10.  
  11.         static void Main(string[] args)
  12.         {
  13.             bool differentbool = false; //MUST BE DECALRED :: Note that it is assigned to false
  14.             test(ref differentbool); //Grab bool from test
  15.             WriteLine(differentbool); //returns true instead of false
  16.  
  17.             bool differentbool2 = false; // Note that it is assigned to false
  18.             yo(differentbool2); //sent bool to yo
  19.             WriteLine(differentbool2); //returns false (no reference, no idea what mybool is in yo)
  20.         }
  21.         static void test(ref bool mybool)
  22.         {
  23.             mybool = true;
  24.         }
  25.         static void yo(bool mybool)
  26.         {
  27.              mybool = true;
  28.         }
  29.     }
  30. }
  31.  
  32.  
  33.  
Add Comment
Please, Sign In to add comment