Rozbalené vlastnosti nelze inicializovat.

Automaticky implementovanou vlastnost lze inicializovat jako součást deklarace, ale rozbalenou vlastnost nemůže být.

ID chyby: BC36714

Oprava této chyby

  • Buď použijte automaticky implementovanou vlastnost, nebo odeberte inicializaci z deklarace vlastnosti.

Příklad

Následující příklady ukazují automaticky implementované i rozbalené vlastnosti. Automaticky implementované vlastnosti lze inicializovat pomocí přiřazení nebo New klauzule, ale rozšířené vlastnosti nemohou být.

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  

Viz také