已声明匿名类型成员或属性“<propertyname>”

更新:2007 年 11 月

在匿名类型声明中只能建立一次属性名称。例如,下面的声明无效:

'' Not valid, because the Label property is assigned to twice.
' Dim anonType1 = New With {.Label = "Debra Garcia", .Label = .Label & ", President"}
'' Not valid, because the property name inferred for both properties is
'' Name.
' Dim anonType2 = New With {Key product.Name, Key car1.Name}

**错误 ID:**BC36547

更正此错误

  • 为一个属性选择不同的名称。

    ' Valid.
    Dim anonType3 = New With {.Name = "Debra Garcia", .Label = .Name & ", President"}
    
  • 为从中推断名称和值的变量或属性名称提供新名称。

    ' Valid.
    Dim anonType4 = New With {Key .ProductName = product.Name, Key .CarName = car1.Name} 
    

请参见

任务

如何:推断匿名类型声明中的属性名和类型

概念

匿名类型