According to the definition :
"As interface is not an object by itself ,I can't initialize it.If interface were allowed to declare fileds, then it needs storage location,so we can not declare fields inside interface."
Incase of property say example
when i declare
string SayHello { get; set; }
inside the interface
It is internally hooked as get_SayHello( ) ,set_SayHello()
in IL (when i disassemble i
can see the get and set methods).
My question is still property needs some storage location,then how the property declaration
is allowed inside the interface.
Edit : This is what i understood.As I am new to C#,i am seeking your help.
You're operating on a somewhat faulty assumption, that properties require a backing field. Yes most properties use a backing field but this is certainly not a requirement. I can for instance implement your interface with no backing field as follows
class C1 : IFoo {
public string SayHello {
get { return "Say Hello"; }
set { }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With