When it comes to encapsulation, it is actually the problem of the basic class, which provides the system and the system, the module and the module, the realization means of the interaction between the class and the class.
As a junior GIS programmer, the concept of packaging those macro-based, not to mention, programming often face is "field, properties, methods," which is one of the basic object-oriented concepts.
1. Fields
Typically defined as private, which represents the state information of a class
private string name;
2. Properties
Usually defined as public, representing the external members of the class. Properties are readable, writable, and read-write control is implemented through get and set accessors. If the property is read-only, only the get accessor is implemented, and if the property is writable, the set accessor is implemented. There is also a parameter-containing attribute, called an indexer in C #. Indexers are typically used to facilitate the reference to a class instantiation object.
The code is as follows:
public string Name{get{return Name;} Set{name=value==null? String.empty:value;//name?? String.Empty (null on the left, return to the right operand value, not NULL to return to left operand)}}
In fact, this is directly in the VS2010 is intelligent, check the field → Select the refactoring → package field, so OK.
3. Methods
The method encapsulates the behavior of the class and provides the external representation of the class. Used to provide external interfaces with the internal details of the encapsulation as public methods, and the method of external interaction is usually implemented as publicly. But the operation inside the class is basically implemented by private way, which guarantees the hiding and protecting of internal data. In VS2010, you can also select the code snippet → select Refactor → extract method.