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
- Either use an automatically implemented property or remove the initialization from the property declaration.
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
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: