this will result in a compiler error. When you are
defining an automatic property,
it must support
both read and write functionality.
Interacting with Automatic Properties
Because the compiler will define the private backing field at compile time, the class defining auto-
matic properties will always need to use property syntax to get and set the underlying value. This
is important to note because many programmers make direct use of the private fields
within a
class definition, which is not possible in this case. For example, if the Car type were to override
ToString(), you would need to implement this method using the property name:
class Car
{
public string PetName { get; set; }
public override string ToString()
{
Do'stlaringiz bilan baham: