G
Guest
Hi,
Maybe someone can explain the use of "Me" to me?
The example class CPoint3 uses the Me reference in the output statement:
Console.WriteLine("CPoint3 constructor: {0}", Me)
The text states: "This implicitely invokes the class's ToString method".
This would be clear if Me.ToString was used, which I tested and works too!.
Actually, Me.Anything works and gives the same results as long as Anything
is a class member.
The class contains 4 methods (2 constructors, Finalize and ToString, two
properties).
What does the Me reference in the output statement exactly all invoke?
1. Does it call all methods but does only the ToString method lead to
printed text since it generates a string representation?
2. The Me reference cannot invoke other methods than the ToString method?
(Does not sound likely!)
Thanks for your explanation,
John
*******
' Fig. 9.16: Point3.vb
' CPoint3 class represents an x-y coordinate pair.
Public Class CPoint3
' point coordinate
Private mX, mY As Integer
' default constructor
Public Sub New()
' implicit call to Object constructor occurs here
X = 0
Y = 0
Console.WriteLine("CPoint3 constructor: {0}", Me)
End Sub ' New
' constructor
Public Sub New(ByVal xValue As Integer, _
ByVal yValue As Integer)
' implicit call to Object constructor occurs here
X = xValue
Y = yValue
Console.WriteLine("CPoint3 constructor: {0}", Me)
End Sub ' New
' finalizer overrides version in class Object
Protected Overrides Sub Finalize()
Console.WriteLine("CPoint3 Finalizer: {0}", Me)
MyBase.Finalize() ' call Object finalizer
End Sub ' Finalize
' property X
Public Property X() As Integer
Get
Return mX
End Get
Set(ByVal xValue As Integer)
mX = xValue ' no need for validation
End Set
End Property ' X
' property Y
Public Property Y() As Integer
Get
Return mY
End Get
Set(ByVal yValue As Integer)
mY = yValue ' no need for validation
End Set
End Property ' Y
' return String representation of CPoint3
Public Overrides Function ToString() As String
Return "[" & mX & ", " & mY & "]"
End Function ' ToString
End Class ' CPoint3
Maybe someone can explain the use of "Me" to me?
The example class CPoint3 uses the Me reference in the output statement:
Console.WriteLine("CPoint3 constructor: {0}", Me)
The text states: "This implicitely invokes the class's ToString method".
This would be clear if Me.ToString was used, which I tested and works too!.
Actually, Me.Anything works and gives the same results as long as Anything
is a class member.
The class contains 4 methods (2 constructors, Finalize and ToString, two
properties).
What does the Me reference in the output statement exactly all invoke?
1. Does it call all methods but does only the ToString method lead to
printed text since it generates a string representation?
2. The Me reference cannot invoke other methods than the ToString method?
(Does not sound likely!)
Thanks for your explanation,
John
*******
' Fig. 9.16: Point3.vb
' CPoint3 class represents an x-y coordinate pair.
Public Class CPoint3
' point coordinate
Private mX, mY As Integer
' default constructor
Public Sub New()
' implicit call to Object constructor occurs here
X = 0
Y = 0
Console.WriteLine("CPoint3 constructor: {0}", Me)
End Sub ' New
' constructor
Public Sub New(ByVal xValue As Integer, _
ByVal yValue As Integer)
' implicit call to Object constructor occurs here
X = xValue
Y = yValue
Console.WriteLine("CPoint3 constructor: {0}", Me)
End Sub ' New
' finalizer overrides version in class Object
Protected Overrides Sub Finalize()
Console.WriteLine("CPoint3 Finalizer: {0}", Me)
MyBase.Finalize() ' call Object finalizer
End Sub ' Finalize
' property X
Public Property X() As Integer
Get
Return mX
End Get
Set(ByVal xValue As Integer)
mX = xValue ' no need for validation
End Set
End Property ' X
' property Y
Public Property Y() As Integer
Get
Return mY
End Get
Set(ByVal yValue As Integer)
mY = yValue ' no need for validation
End Set
End Property ' Y
' return String representation of CPoint3
Public Overrides Function ToString() As String
Return "[" & mX & ", " & mY & "]"
End Function ' ToString
End Class ' CPoint3