What does the error: "Expression recursively calls the containing property 'length'" mean?

StackOverflow https://stackoverflow.com/questions/23638012

  •  21-07-2023
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top