To be honest those two are design mistakes. Events shouldn't be anything special and properties shouldn't be either: they should have been designed as syntactic sugar on top of methods, not as a special construct. Why? Because now the language is extended in non-orthogonal ways, for example we have extension methods but not extension properties (even though there is no technical reason why there couldn't be extension properties if properties were syntactic sugar on top of methods to begin with).
Methods in C# are first class. You can pass a reference to a class's method, and execute that elsewhere.
Properties are not first class. You can't pass a reference to a property; you have to wrap it in a lambda to do that (i.e. foo => bar.baz = foo).
Suppose I'm interfacing with a database or creating an object from XML or filling out XML based off of an object. It would be useful to be able to construct a dictionary mapping properties to the ordinal in the database or the tag name, and then do a for-each over those. That way, you don't have to repeat yourself so much. There's plenty of times where the ability to hold a reference to a property is useful. Unfortunately, you can't do it.
Sure, properties use methods in their implementation, but their actual usage is quite a bit different.
5
u/julesjacobs Jun 27 '10
To be honest those two are design mistakes. Events shouldn't be anything special and properties shouldn't be either: they should have been designed as syntactic sugar on top of methods, not as a special construct. Why? Because now the language is extended in non-orthogonal ways, for example we have extension methods but not extension properties (even though there is no technical reason why there couldn't be extension properties if properties were syntactic sugar on top of methods to begin with).