Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Daniel Solis - Illustrated C# 2010 - 2010.pdf
Скачиваний:
20
Добавлен:
11.06.2015
Размер:
11 Мб
Скачать
☆

CHAPTER 3 TYPES, STORAGE, AND VARIABLES

User-Defined Types

Besides the 15 predefined types provided by C#, you can also create your own user-defined types. There are six kinds of types you can create. They are the following:

•class types

•struct types

•array types

•enum types

•delegate types

•interface types

You create a type using a type declaration, which includes the following information:

•The kind of type you are creating

•The name of the new type

•A declaration (name and specification) of each of the type’s members—except for array and delegate types, which don’t have named members

Once you’ve declared a type, you can create and use objects of the type just as if they were predefined types. Figure 3-5 summarizes the use of predefined and user-defined types. Using predefined types is a one-step process in which you simply instantiate the objects of that type. Using user-defined types is a two-step process. You must first declare the type and then instantiate objects of the type.

Figure 3-5. The predefined types require instantiation only. The user-defined types require two steps:

declaration and instantiation.

38

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]