Private access specifier allows a class to hide its member variables and member functions from other functions and objects. - CSharp Custom Type

CSharp examples for Custom Type:access level

Description

Private access specifier allows a class to hide its member variables and member functions from other functions and objects.

Demo Code

using System;//from w ww  .  ja v  a2s  .  c om
class Rectangle {
   private double length;
   private double width;
   public void Acceptdetails() {
      Console.WriteLine("Enter Length: ");
      length = Convert.ToDouble(Console.ReadLine());
      Console.WriteLine("Enter Width: ");
      width = Convert.ToDouble(Console.ReadLine());
   }
   public double GetArea() {
      return length * width;
   }
   public void Display() {
      Console.WriteLine("Length: {0}", length);
      Console.WriteLine("Width: {0}", width);
      Console.WriteLine("Area: {0}", GetArea());
   }
}
class ExecuteRectangle {
   static void Main(string[] args) {
      Rectangle r = new Rectangle();
      r.Acceptdetails();
      r.Display();
      Console.ReadLine();
   }
}

Result


Related Tutorials