ACCESS MODIFIERS IN C#
Types Vs Type Members
In C# there are 5 different access modifiers in c#
1.Private
2.Protected
3.Internal
4. Protected Internal
5. Public
Private members are available only with in the containing type, where as public members are available any where. There is no restricction.
Protected Members are available, with in the containing type and to the types that derive from the containing type
Access Modifier Accessibility
Private -> Only with in the containing class
Public -> Any where, No Restrictions
Protected -> With in the containing types and the types derived from the
containing type.
————————————————————————————————————————-
using System;
using System.IO;
namespace ConsoleApplication4
{
//public class Customer
//{
// private int _id;
// public int Id
// {
// get { return _id; }
// set { _id = value; }
// }
//}
public class Customer
{
protected int _id;
}
public class corporateCustomer : Customer
{
public void printID()
{
corporateCustomer cc = new corporateCustomer();
cc._id = 101;
}
}
public class Program
{
public static void Main()
{
Customer C1 = new Customer();
Console.WriteLine(C1._id);
}
}
}
————————————————————————————————————————-
INTERNAL AND PROTECTED INTERNAL ACCESS MODIFIERS IN C#