Information Technology Reference
In-Depth Information
Instance Members
A class declaration acts as a blueprint from which you can create as many instances of the class
as you like.
￿
Instance members : Each instance of a class is a separate entity that has its own set of the
class members, distinct from the other instances of the same class. These are called
instance members since they are associated with an instance of the class.
￿
Static members : Instance members are the default, but you can also declare members
that are associated with the class, rather than the instance. These are called static mem-
bers , and they will be looked at in Chapter 6.
For example, the following code shows the poker program with three instances of class
Player . Each instance has a different value for the Name field. The code is illustrated in Figure 4-4.
class Dealer { ... } // Declare class
class Player { // Declare class
string Name; // Field
...
}
class Program {
static void Main()
{
Dealer TheDealer = new Dealer();
Player Player1 = new Player();
Player Player2 = new Player();
Player Player3 = new Player();
...
}
}
Figure 4-4. Instance members are distinct between class objects.
Search WWH ::




Custom Search