Question

Sometimes when I add a property to class like this:

Public Class Ship
    Public Property name() As String
        Get
            Return Me.name
        End Get
        Set(ByVal value As String)

        End Set
    End Property

I get an error. When I delete and retype it, sometimes the error doesn't appear. What causes an error like this?

Was it helpful?

Solution

You are hitting a potential stack overflow.

You need a private member to back your property or an automatic property.

Public Class Ship
    Dim _name As String
    Public Property name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top