1. private - private members are available only with in the containing type / only with in the containing class (default for type members)
2. protected - with in the containing types and the types derived from the containing type
3. internal - Anywhere with in the containing assembly (default for types)
4. protected internal - anywhere with in the containing assembly / and from within a derived class in any another assembly
5. public - public members are available any where / anywhere, no restrictions
==================================
using System;
public class Customer
{
private int _id;
public int ID
{
get
{
return _id;
}
set
{
_id = value;
}
}
}
class MainClass
{
static void Main(string[] args)
{
Customer C1 = new Customer();
//Console.WriteLine(C1._id); can't use as of private
Console.WriteLine(C1.ID); // possible as of public
}
}
=================================
using System;
public class Customer
{
protected int ID;
}
public class CorporateCustomer : Customer
{
public void PrintID()
{
CorporateCustomer cc = new CorporateCustomer();
cc.ID = 101; // possible as of derived class
//base.ID = 101; other way
//this.ID = 101; another way
}
}
class MainClass
{
static void Main(string[] args)
{
Customer C1 = new Customer();
//Console.WriteLine(C1.ID); // can't use as of protected and not derived class
}
}
===================================
AssemblyOne - class library
using System;
namespace AssemblyOne
{
public class AssemblyOneClass1
{
protected internal int ID = 101;
}
public class AssemblyOneClass2
{
public void SampleMethod()
{
AssemblyOneClass1 A1 = new AssemblyOneClass1();
Console.WriteLine(A1.ID);
}
}
}
AssemblyTwo - class library
using System;
using AssemblyOne;
namespace AssemblyTwo
{
public class AssemblyTwoClass1 : AssemblyOneClass1
{
public void Print()
{
AssemblyOneClass1 A1 = new AssemblyOneClass1();
base.ID = 101;
AssemblyTwoClass1 A2 = new AssemblyTwoClass1();
A2.ID = 101; // as of proted internal
}
}
}
What is default of access modifier in type members - private
what is default of access modifier in types - internal