Y
YellowDog
I want to use a property without a private data member. This is
supposed to be legal, except that I get an Stack Overflow Exception
when I implicity use the set method. Here's the code:
Option Explicit
Option Strict On
Imports System
Public Class PropertyT
' Private LocalAge as Integer = 24
Public Property LocalAge() As Integer
Get
Return LocalAge
End Get
Set (ByVal value As Integer)
LocalAge = value
End Set
End Property
End Class
Public Class PropertyConsumer
Public Shared Sub Main()
Try
Dim t As New PropertyT()
Console.WriteLine("t's Age is {0}", t.LocalAge)
t.LocalAge = 25
Console.WriteLine("t's Age is {0}", t.LocalAge)
Catch e As StackOverflowException
Console.WriteLine(e.Message)
End Try
End Sub
End Class
=========
And here's the output.
t's Age is 0
Exception of type System.StackOverflowException was thrown.
supposed to be legal, except that I get an Stack Overflow Exception
when I implicity use the set method. Here's the code:
Option Explicit
Option Strict On
Imports System
Public Class PropertyT
' Private LocalAge as Integer = 24
Public Property LocalAge() As Integer
Get
Return LocalAge
End Get
Set (ByVal value As Integer)
LocalAge = value
End Set
End Property
End Class
Public Class PropertyConsumer
Public Shared Sub Main()
Try
Dim t As New PropertyT()
Console.WriteLine("t's Age is {0}", t.LocalAge)
t.LocalAge = 25
Console.WriteLine("t's Age is {0}", t.LocalAge)
Catch e As StackOverflowException
Console.WriteLine(e.Message)
End Try
End Sub
End Class
=========
And here's the output.
t's Age is 0
Exception of type System.StackOverflowException was thrown.