c# properties on Interface [closed]

Properties are syntactic sugar for methods. Consider this:

I have a property:

String PropertyA { get; set; } 

At runtime this becomes something like this:

String get_PropertyA() { ... }
void set_PropertyA(String value) { ... }

Note that the “…” indicates code that would be put there by the code generator. Effectively what I am saying is that properties don’t really exist beyond C#, as they compile down to methods using a convetion indicated in my example. To confirm what I am saying you can use reflection and have a look at what the reflected code looks like.

It can be bad practice however to put properties on an interface if they do something that is non trivial in the implementation. For example, if I want to set a variable and that updates other variables, or setting a property might deny my property assignment because of an internal condition, then a property shouldn’t be used. I think that is a general rule that would apply beyond interfaces.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)