Reputation: 39427
One of the advantages that i hear about properties is that they can be used for databinding, while i hear no explanation of why beyond "that's how it works". Is it that way because there is no choice (i.e. a limitation of the .NET VM) or was it really designed that way, and if so why?
Upvotes: 1
Views: 110
Reputation: 1499880
Using properties instead of public fields is good practice - I would imagine that when data binding was being designed, they chose to try to encourage that good practice. Allowing fields to be bound directly would be tantamount to saying that the separation between interface and implementation didn't matter, and that it was fine to just expose everything publicly.
That's just a guess, mind you.
Although there's PropertyDescriptor
there could equally have been FieldDescriptor
, and you can fetch fields by reflection just as easily as properties... so I doubt that it was a technical problem.
Upvotes: 1