Edit

Share via


Expanded properties cannot be initialized

An auto-implemented property can be initialized as part of its declaration, but an expanded property cannot be.

Error ID: BC36714

To correct this error

  • Either use an automatically implemented property or remove the initialization from the property declaration.

Example

The following examples show both automatically implemented and expanded properties. Automatically implemented properties can be initialized by using assignment or a New clause, but expanded properties cannot be.

VB
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  

See also