public class Person
{
private string _name; // always recommended to be private
private static string s_homePlanet; // recommended?
}
As mentioned in the question the practice of encapsulation recommends that I always declare my instance fields as private
. To keep an instance's information as hidden.
According to Fields (C# Programming Guide)
"Generally, you should use fields only for variables that have private or protected accessibility."
According to C# Field Design
"The principle of encapsulation is one of the most important notions in object-oriented design. This principle states that data stored inside an object should be accessible only to that object. This interpretation immediately implies that all fields must be private."
I know a static field stores information that is shared amongst instances of a type; thus, the informaton stored within a static field is not specific to any instance. With that being said is it reccomded that I always declare a static field as private
???