// No access to the private member in the defining
// class. Must use properties!
return string.Format("PetName = {0}", PetName);
}
}
When you are using an object defined with automatic properties, you will be able to assign and
obtain the values using the expected property syntax:
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Automatic Properties *****");
Car c = new Car();
c.PetName = "Frank";
Console.WriteLine("Your car is named {0}? That's odd...",
c.PetName);
Console.ReadLine();
}
Restricting Access on Automatic Properties
Recall that a “normal” .NET property can be constructed in such a way that the get and set logic is
assigned a unique access modifier. For example, it is possible to define a public get scope and a
more restrictive protected scope as follows:
Do'stlaringiz bilan baham: |