The declaration of a property in an interface says that any implementing class must have such methods (get_SayHello
and set_SayHello
but defined as properties) but does not specify how they are implemented. That is, the interface says what you can do, but now how it is done (so you can get the SayHello
"string", and you can set the SayHello
"string"). So, to be specific: defining a property in an interface says nothing about backing fields.
Also, it is a misconception that properties have to have backing fields. The following does not:
class Example {
public string SayHello {
get {
return "Hello, World!";
}
set { }
}
}
Properties are just methods that are accessible via field-like syntax. As they are methods, and not fields, they are defineable an interface.