无法在对象初始值设定项表达式中初始化成员“<membername>”,因为它是共享成员

更新:2007 年 11 月

不能使用对象初始值设定项初始化类的任何被声明为共享成员的成员。有关更多信息,请参见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)