Las propiedades expandidas no se pueden inicializar

Se puede inicializar una propiedad implementada automáticamente como parte de su declaración, pero no una propiedad expandida.

Identificador de error: BC36714

Para corregir este error

  • Use una propiedad implementada automáticamente o quite la inicialización de la declaración de propiedad.

Ejemplo

En los ejemplos siguientes se muestran las propiedades implementadas y expandidas automáticamente. Las propiedades implementadas automáticamente se pueden inicializar mediante la asignación o una New cláusula , pero las propiedades expandidas no pueden ser.

Class AutoImplementedExample  
    ' An automatically implemented property can be assigned an initial value.  
    Property IDNum As Integer = 33542  
    ' An automatically implemented property can be initialized with New.  
    Property Name As New String("Don Hall")  
End Class  
  
Class ExpandedExample  
    ' Attempting to expand an initialized automatically implemented property  
    ' causes this error.  
    'Property IDNum As Integer = 33542  
    '    Get  
    '    End Get  
    '    Set(ByVal value As Integer)  
    '    End Set  
    'End Property  
  
    ' Instead, you can assign the initial value to the backing field.  
    Private _IDNum As Integer = 33542  
    Property IDNum As Integer  
        Get  
        End Get  
        Set(ByVal value As Integer)  
        End Set  
    End Property  
End Class  

Consulte también