"Herfried K. Wagner [MVP]"
... by understanding 'With' and type casts ;-).
Will you than explain the ils from main beneath of this sample for me?.
\\\testprogram
Public Class thisClass
Public Shared Sub main()
Dim we As New mytopclass
we = New mysubclass
Dim comments As String = "Start of Directcast"
comments = DirectCast(we, mysubclass).he
comments = "Start of With"
With DirectCast(we, mysubclass)
comments = .he
End With
comments = "Start of setting an adress holder"
Dim c1 As mysubclass = DirectCast(we, mysubclass)
comments = c1.he
comments = "End comments"
End Sub
End Class
Public Class mytopclass
End Class
Public Class mysubclass
Inherits mytopclass
Public Shared ReadOnly Property he() As String
Get
Return "Herfried"
End Get
End Property
End Class
///
\\\Ils from the mainmethode for this
..method public static void main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01
00 00 00 )
// Code size 71 (0x47)
.maxstack 1
.locals init (class WindowsApplication3.mysubclass V_0,
string V_1,
class WindowsApplication3.mytopclass V_2,
class WindowsApplication3.mysubclass V_3)
IL_0000: newobj instance void WindowsApplication3.mytopclass::.ctor()
IL_0005: stloc.2
IL_0006: newobj instance void WindowsApplication3.mysubclass::.ctor()
IL_000b: stloc.2
IL_000c: ldstr "Start of Directcast"
IL_0011: stloc.1
IL_0012: call string WindowsApplication3.mysubclass::get_he()
IL_0017: stloc.1
IL_0018: ldstr "Start of With"
IL_001d: stloc.1
IL_001e: ldloc.2
IL_001f: castclass WindowsApplication3.mysubclass
IL_0024: stloc.3
IL_0025: call string WindowsApplication3.mysubclass::get_he()
IL_002a: stloc.1
IL_002b: ldnull
IL_002c: stloc.3
IL_002d: ldstr "Start of setting an adress holder"
IL_0032: stloc.1
IL_0033: ldloc.2
IL_0034: castclass WindowsApplication3.mysubclass
IL_0039: stloc.0
IL_003a: call string WindowsApplication3.mysubclass::get_he()
IL_003f: stloc.1
IL_0040: ldstr "End comments"
IL_0045: stloc.1
IL_0046: ret
} // end of method thisClass::main
///
Do not ask me to explain it, I did not make that statement as you.
Cor