#698 – Type Members Are Implicitly Private
October 23, 2012 Leave a comment
You use access modifiers to define the accessibility of members within a class (public, private, protected, internal or protected internal).
If you omit the access modifier entirely, the class member defaults to being private. This is true for all class members, including constants, fields, properties, methods, indexers, events, constructors and nested types.
In the example below, the Description property, NumDogs static property and the ChaseTail method are all effectively private members, because their declaration does not include an access modifier.
public class Dog { // Public properties public string Name { get; set; } public int Age { get; set; } // Implicitly private string Description { get; set; } // Instance constructor public Dog(string name, int age) { Name = name; Age = age; } // Implicitly private static int NumDogs { get; set; } // Implicitly private void ChaseTail() { Console.WriteLine("I'm chasing my tail"); } }