Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. static void referencia(ref int y) //Quan cridem aquesta funció la y del main s'incrementa en 1 pq li hem passat la variable per referencia
  2. {
  3. y += 1;
  4. }
  5.  
  6. static void no_referencia(int y) //Quan cridem aquesta funció la y del main es queda igual pq li hem passat una copia
  7. {
  8. y += 1;
  9. }
  10.  
  11. static void main(string[] args)
  12. {
  13. int y = 1;
  14.  
  15. referencia(y); //retorna y = 2
  16.  
  17. y = 1;
  18. no_referencia(y); // retorna y = 1
  19.  
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement