Advertisement
svetlai

ref example

Feb 12th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. namespace Score
  2. {
  3.     using System;
  4.  
  5.     public class RefExample
  6.     {
  7.         public static void Main()
  8.         {
  9.             int score = 0;
  10.  
  11.             // no ref
  12.             //IncreaseScoreNoRef(score);
  13.             //Console.WriteLine(score);
  14.  
  15.             // ref
  16.             IncreaseScoreRef(ref score);
  17.             Console.WriteLine(score);
  18.         }
  19.  
  20.         public static void IncreaseScoreRef(ref int score)
  21.         {
  22.             score += 10;
  23.         }
  24.  
  25.         public static void IncreaseScoreNoRef(int score)
  26.         {
  27.             score += 10;
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement