【问题标题】:why are some .NET methods written wrapped in brackets? [duplicate]为什么有些 .NET 方法用括号括起来? [复制]
【发布时间】:2014-02-11 03:29:37
【问题描述】:

我是编程新手,这可能是一个非常基本的问题,但我想知道 [TestMethod] 和 [CodedUITest] 等放在 [括号] 中的哪些项目被调用,以及它们在 .NET 中的作用。为什么这些方法都是这样写的?

谢谢

【问题讨论】:

标签: c# .net coded-ui-tests


【解决方案1】:

那些被称为Attributes。它们为您的代码元数据提供 IDE 可用于执行诸如了解哪些方法是单元测试、如何序列化类或在智能提示提示中首先显示什么等事情。

【讨论】:

  • IDE 和编译器以及 CLR 和其他东西** :)
【解决方案2】:

它们是属性

Attributes can be placed on most any declaration, though a 
specific attribute might restrict the types of declarations on which it is valid.
In C#, you specify an attribute by placing the name of the attribute, enclosed in square brackets ([]), above 
the declaration of the entity to which it applies. In Visual Basic, an attribute
is enclosed in angle brackets (< >). It must appear immediately before the element to 

它被应用, 在同一行。

Attributes

Introduction to Attributes

【讨论】:

    猜你喜欢
    • 2011-08-14
    • 2012-02-21
    • 2022-11-10
    • 2012-02-12
    • 2020-07-02
    • 2012-09-03
    • 2012-09-12
    • 1970-01-01
    相关资源
    最近更新 更多