Guest User

Untitled

a guest
Dec 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. class Example {
  2.  
  3.     public static void Main() {
  4.         int variable = 0;
  5.         bool success = SomeProcedureWithRef(ref variable);
  6.         // At this point success == true, variable == 10
  7.  
  8.         // This declaration is ok because after the call outVariable must have been set
  9.         int outVariable;
  10.         bool success = SomeProcedureWithOut(out outVariable);
  11.         // At this point success == false, variable == 20
  12.     }
  13.  
  14.     public static bool SomeProcedureWithRef(ref int value) {
  15.         value = 10; // This is optional (but often helpful)
  16.         return true;
  17.     }
  18.  
  19.     public static bool SomeProcedureWithOut(out int value) {
  20.         value = 20; // Compile time error if not setting value
  21.         return false;
  22.     }
  23.  
  24. }
Add Comment
Please, Sign In to add comment