Non è possibile inizializzare le proprietà espanse

Una proprietà implementata automaticamente può essere inizializzata come parte della relativa dichiarazione, mentre questo non è possibile per una proprietà espansa.

ID errore: BC36714

Per correggere l'errore

  • Usare una proprietà implementata automaticamente o rimuovere l'inizializzazione dalla dichiarazione di proprietà.

Esempio

Negli esempi seguenti vengono mostrate sia le proprietà implementate automaticamente che le proprietà espanse. Le proprietà implementate automaticamente possono essere inizializzate usando l'assegnazione o una New clausola , ma le proprietà espanse non possono essere.

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  

Vedi anche