Last active
August 29, 2015 14:03
-
-
Save svenoaks/998d9bc7d5dcc12015e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Module Module1 | |
Dim GlobalWord As String | |
Class PersonType | |
Public Sub New() | |
SecretName = "hushhush" | |
End Sub | |
Public Property FirstName As String | |
Public Property LastName As String | |
Private Property SecretName As String | |
Public Function AskMeMySecretName() As String | |
Return SecretName | |
End Function | |
End Class | |
Sub Main() | |
Dim PersonA As New PersonType | |
Dim PersonB As New PersonType | |
'These Properties can be retrieved or set from anywhere because | |
'they are declared as public. | |
'Notice how each instance of the class as it's own FirstName and | |
'LastName variable. | |
PersonA.FirstName = "Steve" | |
PersonA.LastName = "M" | |
PersonB.FirstName = "Dan" | |
PersonB.LastName = "W" | |
'The below will not compile because SecretName is Private and cannot | |
'be accessed from outside. | |
' PersonA.SecretName = "Svenski" | |
GlobalWord = "hola" | |
Dim LocalWord = "hello" | |
Aux() | |
'We can get PersonAs SecretName by calling a public Function that | |
'returns it. | |
Dim PersonASecretName As String = PersonA.AskMeMySecretName() | |
Console.WriteLine("PersonA's first name is " & PersonA.FirstName & ". " & | |
"PersonB's first name is " & PersonB.FirstName & ". " & | |
"GlobalWord is " & GlobalWord & ".") | |
Console.WriteLine("PersonA's super secret name is " & PersonASecretName) | |
Console.ReadKey() | |
End Sub | |
Sub Aux() | |
' GlobalWord can be accessed from anywhere, but LocalWord is local to Main(). | |
' Likewise, PersonA and PersonB objects are local to Main(). | |
GlobalWord = "something else" | |
' Won't compile | |
' LocalWord = "blah" | |
End Sub | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment