2014-02-11 29 views
0

我是編程新手,這可能是一個非常基本的問題,但我想知道放置[括號]內的項目,如[TestMethod]和[CodedUITest]是否被調用,以及它們在.NET中的作用。爲什麼這些方法是用這種方式寫的?爲什麼一些.NET方法寫在括號中?

謝謝

+0

http://stackoverflow.com/questions/2968597/what-is-brackets-in-net – Trent

+1

看一看[屬性](http://stackoverflow.com/questions/20346/net-what-are-attributes) – StuartLC

回答

5

這些被稱爲Attributes。他們給你的代碼元數據IDE可以用來做的事情,比如知道哪些方法是單元測試,如何序列化一個類,或者在intellisense提示中首先顯示什麼。

+0

IDE和編譯器以及CLR和其他東西** :) –

3

它們屬性

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

相關問題