Information Technology Reference
In-Depth Information
User-Defined Types
Besides the 15 predefined types provide by C#, you can also create your own types, called
user-
defined types
.
There are six
kinds of types
you can create, as follows:
class
types
num
types
struct
types
delegate
types
array
types
interface
types
Types are created 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 do not have named members
Once you have declared a type, you can create and use objects of the type just as if they
were predefined types. But whereas using predefined types is a one-step process in which you
simply instantiate the objects, using user-defined types is a two-step process. You first declare
the type and then instantiate objects of the type. This is illustrated in Figure 3-5.
Figure 3-5.
The predefined types require instantiation only. The user-defined types require two
steps: declaration and instantiation.