NelloRizzo

[VBNET] Passaggio dei parametri

Feb 14th, 2017
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.99 KB | None | 0 0
  1. Module Module1
  2.  
  3.     Sub Incr(ByVal x As Integer)
  4.         x += 1
  5.         Console.WriteLine("Dentro Incr, x vale {0}", x)
  6.     End Sub
  7.  
  8.     Sub IncrR(ByRef x As Integer)
  9.         x += 1
  10.         Console.WriteLine("Dentro IncrR, x vale {0}", x)
  11.     End Sub
  12.  
  13.     Class MyInt
  14.         Public Property Value As Integer
  15.     End Class
  16.  
  17.     Sub Incr(x As MyInt)
  18.         x.Value += 1
  19.         Console.WriteLine("Dentro incr, Value vale {0}", x.Value)
  20.     End Sub
  21.  
  22.     Sub Main()
  23.         Dim y As Integer = 10
  24.         Console.WriteLine("Prima di chiamare Incr, y vale {0}", y)
  25.         Incr(y)
  26.         Console.WriteLine("Dopo la chiamata a Incr, y vale {0}", y)
  27.         IncrR(y)
  28.         Console.WriteLine("Dopo la chiamata a IncrR, y vale {0}", y)
  29.         Dim a As New MyInt With {.Value = 10}
  30.         Console.WriteLine("Prima di incr, Value vale {0}", a.Value)
  31.         Incr(a)
  32.         Console.WriteLine("dopo incr, Value vale {0}", a.Value)
  33.  
  34.         Console.ReadLine()
  35.     End Sub
  36.  
  37. End Module
Add Comment
Please, Sign In to add comment