|
|
|
|
|
by int_19h
3534 days ago
|
|
That'll be about as long as Java, sure. But most properties that are actually written in code don't need validation. In fact, most of them don't even have a setter. In C#, this means that I can do: public Foo Foo { get; }
or for a computed property: public int Foo => Bar + 1;
The real savings from property come when you use them, though - the extra pair of () doesn't feel like much, but when you start chaining properties, I find that not having () there significantly improves readability. Then, of course, Java also insists on `get` prefix by convention. So you have Java: foo.getBar().getBaz().blah()
vs C#: foo.Bar.Baz.Blah()
More importantly, the latter visually emphasizes the difference between accessing data and operating on it. You can see that "Bar" and "Baz" are data members, conceptually similar to "foo", whereas "blah()" is an operation. |
|