Break OO privacy: Difference between revisions

Line 1,230:
Hello, I am Eric
Hello, I am Edith
 
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|F#}}
 
Like the other .NET languages, VB can use Reflection ([https://docs.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/reflection Microsoft docs]).
 
<lang vbnet>Imports System.Reflection
 
' MyClass is a VB keyword.
Public Class MyClazz
Private answer As Integer = 42
End Class
 
Public Class Program
Public Shared Sub Main()
Dim myInstance = New MyClazz()
Dim fieldInfo = GetType(MyClazz).GetField("answer", BindingFlags.NonPublic Or BindingFlags.Instance)
Dim answer = fieldInfo.GetValue(myInstance)
Console.WriteLine(answer)
End Sub
End Class</lang>
 
{{out}}
<pre>42</pre>
 
=={{header|zkl}}==
Anonymous user