Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I databind to a field?

I've just learnt (the hard way) that databinding doesn't work with fields. This isn't a problem given how easy automatic properties are, but I was wondering why this is the case. Can anyone explain?

like image 556
Jon Artus Avatar asked Nov 16 '25 13:11

Jon Artus


1 Answers

I found a good explanation here:

... because public fields are not a recommended practice. While they maybe convenient for quick and dirty code, they do not version. Using properties instead allows you to change the access logic, and data storage behind the covers, as well as add validation logic when a value is assigned. Furthermore, accessing properties feels pretty much the same, and do not have any performance overhead.

like image 79
bruno conde Avatar answered Nov 19 '25 04:11

bruno conde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!