Advertisement
NelloRizzo

[VBNET] Interfacce

Feb 17th, 2017
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.04 KB | None | 0 0
  1. Module Module1
  2.  
  3.     Class C
  4.         Implements IDisposable
  5.  
  6.         Public Sub Close() Implements IDisposable.Dispose
  7.             Console.WriteLine("Closing...")
  8.         End Sub
  9.     End Class
  10.  
  11.     Class Person
  12.         Public Property Name As String
  13.         Public Function GetName() As String
  14.             Return Name
  15.         End Function
  16.         Public Overrides Function ToString() As String
  17.             Return Name
  18.         End Function
  19.     End Class
  20.  
  21.     Class Student
  22.         Inherits Person
  23.         Implements PostOfficeUser
  24.  
  25.         Public Property Matr As String
  26.  
  27.         Function ShowMeInPostOffice() As String Implements PostOfficeUser.ShowMe
  28.             Return "sono uno studente e mi chiamo " + Name
  29.         End Function
  30.  
  31.         Public Shadows Function GetName() As String
  32.             Return Name & " - Matr: " & Matr
  33.         End Function
  34.         Public Overrides Function ToString() As String
  35.             Return MyBase.ToString() & " - Matr: " & Matr
  36.         End Function
  37.     End Class
  38.  
  39.     Sub PrintPerson(p As Person)
  40.         Console.WriteLine("Chiamando ToString: {0}", p)
  41.         Console.WriteLine("Chiamando GetName: {0}", p.GetName())
  42.     End Sub
  43.  
  44.     Interface PostOfficeUser
  45.         Function ShowMe() As String
  46.     End Interface
  47.  
  48.     Sub PostOfficePresentation(e As PostOfficeUser)
  49.         Console.WriteLine(e.ShowMe())
  50.     End Sub
  51.  
  52.     Sub Main()
  53.         Dim p As New Person() With {.Name = "Paperino"}
  54.         Dim s As New Student() With {.Name = "Qui", .Matr = "12345"}
  55.         PrintPerson(p)
  56.         PrintPerson(s)
  57.         Console.WriteLine("GetName di Student: {0}", s.GetName())
  58.         'PostOfficePresentation(p)
  59.         PostOfficePresentation(s)
  60.         Console.ReadLine()
  61.     End Sub
  62.  
  63.     Sub Main1()
  64.         Using f As New System.IO.FileStream("pippo", System.IO.FileMode.Create)
  65.  
  66.         End Using
  67.         Using o As New C
  68.             Console.WriteLine("Dentro Using...")
  69.         End Using
  70.         Console.WriteLine("Dopo Using...")
  71.  
  72.  
  73.         Console.ReadLine()
  74.     End Sub
  75.  
  76. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement