다음을 통해 공유


'<membername>' 멤버를 공유하고 있으므로 개체 이니셜라이저 식에서 초기화할 수 없습니다.

업데이트: 2007년 11월

Member '<membername>' cannot be initialized in an object initializer expression because it is shared

공유로 선언된 클래스의 멤버를 초기화하는 데 개체 이니셜라이저를 사용할 수 없습니다. 자세한 내용은 Shared(Visual Basic)를 참조하십시오.

오류 ID: BC30991

이 오류를 해결하려면

  1. 클래스 정의를 검사하여 공유할 멤버를 결정합니다.

  2. 개체 이니셜라이저 목록에서 해당 멤버의 초기화를 제거합니다.

예제

다음 예제에서 totalCustomers는 공유 멤버입니다.

Public Class Customer
    Public Shared totalCustomers As Integer
    ' Other declarations and method definitions.
End Class

totalCustomers는 공유이므로 개체 이니셜라이저 목록에서 해당 초기 값을 설정하려고 하면 이 오류가 발생합니다.

' This declaration is not valid.
' Dim cust As New Customer With { .Name = "Coho Winery", _
'                                 .totalCustomers = 21 }

참고 항목

개념

개체 이니셜라이저: 명명된 형식과 익명 형식

Visual Basic의 공유 멤버

참조

Shared(Visual Basic)