Advertisement
NelloRizzo

[VBNET] Interuttore e lampadina 1

Feb 14th, 2017
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.18 KB | None | 0 0
  1. Module Module1
  2.  
  3.     Delegate Sub InterruttorePremutoDelegate()
  4.  
  5.     Class Interruttore
  6.         Public Property Nome As String
  7.         Public Click As InterruttorePremutoDelegate
  8.  
  9.         Public Sub Premi()
  10.             Click()
  11.         End Sub
  12.     End Class
  13.  
  14.     Class Lampadina
  15.         Public Property Nome As String
  16.         Public Property Accesa As Boolean
  17.         Public Sub GestoreClickSuInterruttore()
  18.             Accesa = Not Accesa
  19.             ' If Accesa Then Write("Accesa") Else Write("SPENTA")
  20.             Console.WriteLine("La lampadina {1} รจ {0}",
  21.                               IIf(Accesa, "Accesa", "Spenta"),
  22.                               Nome)
  23.         End Sub
  24.     End Class
  25.  
  26.     Sub GestoreClick()
  27.         Console.WriteLine("La lampadina si accende e si spegne")
  28.     End Sub
  29.  
  30.     Sub Main()
  31.         Dim s As New Interruttore With {.Nome = "Cucina"}
  32.         Dim l As New Lampadina With {.Nome = "Cucina"}
  33.         's.Click = AddressOf GestoreClick
  34.         s.Click = AddressOf l.GestoreClickSuInterruttore
  35.  
  36.         s.Premi()
  37.         s.Premi()
  38.         s.Premi()
  39.         s.Premi()
  40.         s.Premi()
  41.  
  42.         Console.ReadLine()
  43.     End Sub
  44.  
  45. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement