Information Technology Reference
In-Depth Information
A Type Is a Template
Since a C# program is just a set of type declarations, learning C# consists of learning how to cre-
ate and use types. So the first thing you need to do is to look at what a type is.
You can start by thinking of a type as a template for creating a data structure. It is not the data
structure itself, but it specifies the characteristics of objects constructed from the template.
A type has the following:
￿A name
￿
A data structure to contain its components
￿
Behaviors and constraints
For example, Figure 3-1 illustrates the components of two types: short and int .
Figure 3-1. A type is a template.
Instantiating a Type
Creating an actual object from the type's template is called instantiating the type.
￿
The object created by instantiating a type is called either an object of the type or an
instance of the type. The terms are interchangeable.
￿
Every data item in a C# program is an instance of some type—either a type provided by
the language, provided by the BCL, or defined by the programmer.
Figure 3-2 illustrates the instantiation of objects of two predefined types.
Figure 3-2. Instantiating a type creates an instance.
Search WWH ::




Custom Search