If you're still creating public variables in your types, stop now. You should be using properties as they enable you to create an interface that acts like data access, but still has all of the benefits of a method. They also provide encapsulation, something you want as an object-oriented developer.
The .NET Framework assumes you'll use properties for your public data members. The data binding code classes support properties but do not support public data members. For example:
txtLastName.DataBindings.Add("Text", Employee, "LastName");
This example bind the Text property of "txtLastName" TextBox control to the "LastName" property of the "Employee" object.
As you already know, properties allow you to apply rules as to what data can be applied to your private variables. Properties allow you to apply those rules in one location...much easier to update in the future.
These are just a few reasons why...to read more, pick up "Effective C#: 50 Specific Ways to Improve Your C#" by Bill Wagner.
You can buy it at the Addison-Wesley website:
http://www.aw-bc.com/
Comments
Leave a Comment