Sunday, October 17, 2010

Types of access specifiers in C#. / Understanding the public Access specifier in c#:

C# provide five access specifiers, they are as follows:
  • public
  • private
  • protected
  • internal
  • protected internal

Understanding the public Access specifier in c#:
The public access specifier allows a class to expose its member variables and member function to other functions and objects. Any member that is declared public can be accessed from outside the class. The member can be accessed from anywhere.

The following is an example of the use of public access specifier.

using System;
namespace HelloWorld
{
class hello
{
public int iNum1;
}
class MyMainClass
{
static void Main(string[] args)
{
hello HelloObject = new hello();
HelloObject.iNum1 = 10; /* since variable iNum1 is public it can be accessed in other classes also*/

Console.WriteLine(HelloObject.iNum1);
Console.ReadLine();
}
}
}

Output is display below.
10



C Sharp Access specifier Related Contents.

Understanding The private access specifier in c Sharp.
Understanding The protected access specifier in c Sharp.
Understanding The internal access specifier in c Sharp.
understanding the protected internal Access Specifier in c#:
if...else construct in c sharp.

No comments:

Recent Posts