#315 – Accessibility of Static Methods and Properties
May 2, 2011 Leave a comment
Like instance methods and properties, you can define the accessibility of static methods and properties using access modifiers. As with instance members, access modifiers on static members indicates what code has access to the member.
- public – All code has access
- private – Only code in the defining class has access
- protected – Code in the defining class or derived classes has access
- internal – All code in the defining assembly has access
- protected internal – Code in the defining assembly or in derived classes has access
// All code has access
public static Dog MakeNewDog()
{
}
// Only this class has access
private static void InitSomeStaticData()
{
}
// Subclass has access
protected static void InitOtherStuff()
{
}
// Code in same assembly has access
internal static void RunSomeCalcs()
{
}
// Code in same assembly or subclass has access
protected internal static void DoOtherStuff()
{
}