// Interact with the static property.
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Encapsulation *****\n");
// Set company.
Employee.Company = "Intertech Training";
Console.WriteLine("These folks work at {0}.", Employee.Company);
Employee emp = new Employee("Marvin", 24, 456, 30000, "111-11-1111");
emp.GiveBonus(1000);
emp.DisplayStats();
Console.ReadLine();
}
Finally, recall that classes can support static constructors. Thus, if you wanted to ensure that
the name of the static companyName field was always assigned to “Intertech Training,” you would
write the following:
// Static constructors are used to initialize static data.
public class Employee
{
private Static companyName As string
...
static Employee()
{
companyName = "Intertech Training";
}
}
Using this approach, there is no need to explicitly call the Company property to set the initial
value:
Do'stlaringiz bilan baham: |