VB.NET 属性中的括号

2 vb.net

我正在研究一些工作中的遗留代码,我想知道这两个属性之间有什么区别:

Public Property HasUsedCopies() As Boolean

Public Property HasUsedCopies As Boolean

使用 VB.NET 到 C# 代码转换器,它们是相同的:

public bool HasUsedCopies { get; set; }

括号表示什么?

Jen*_*ens 6

如果您查看第 9.7 节下Visual Basic 语言规范:属性:

PropertyMemberDeclaration ::=
   [ Attributes ] [ PropertyModifier+ ] Property Identifier
      [ ( [ ParameterList ] ) ] [ As TypeName ] [ ImplementsClause ]
      LineTerminator
   [ PropertyAccessorDeclaration+ ]
   [ End Property LineTerminator ]
PropertyModifier ::= ProcedureModifier | Default | ReadOnly | WriteOnly
PropertyAccessorDeclaration ::=
   PropertyGetDeclaration | 
   PropertySetDeclaration
Run Code Online (Sandbox Code Playgroud)

在这里您可以看到参数列表和括号中的括号都是可选的:

[ ( [ ParameterList ] ) ]

所以括号可以省略,因此两个语句是等价的。