Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

ATTRIBUTES AND PROPERTIES

Chapter 5

 

91

 

 

 

 

 

In addition to this classification, properties are classified based on the modifier specified in the property declaration statement. As discussed earlier, property modifiers include access modifiers and the new, static, override, abstract, and sealed modifiers.

Types of Properties

C# supports the following properties based on the type of modifier used in the property declaration statement.

Static property. A property that is declared with a static modifier is a static property. A static property cannot be referred by a specific instance of a class. You cannot use the abstract, override, and virtual modifiers with a static property.

Instance property. A property that is not declared with an explicit static modifier is an instance property. An instance property is referred by a specific instance of a class and is also known as a non-static property.

Summary

In this chapter, you learned about attributes and properties. Attributes are elements used with methods and classes to store additional information about them. Attributes can also be used with the arguments of a method. To retrieve the information stored in attributes, you need to create instances of the Attribute class. All attribute classes are derived from the abstract class Attribute in the System namespace.

Next, you learned about the default attributes provided by C#. These default attributes include the Obsolete, Conditional, and AttributeUsage attributes. The C# compiler explicitly identifies the default parameters provided by C# and compiles the program code accordingly.

Finally, you learned about properties that are used to access an attribute of an element. Each property that you declare has accessors associated with it. These accessors define statements that enable you to read and write values to a property. The accessors used with properties are the get and set accessors.

This page intentionally left blank

Chapter 6

Threads