Implement Encapsulation in C#

March 28, 2019 · Team EasyExamNotes · 1 min read (est.) · 2 comments

Share on WhatsApp
PRINCIPLES OF PROGRAMMING LANGUAGES

PRACT. Implement Encapsulation in C#.
using System;
namespace ATC
{
    class AreaDimension
    {
      public double length;
      private double width;
      
      public double GetWidth() {
         Console.WriteLine(“Enter Width here becuase its private: “);
         width = Convert.ToDouble(Console.ReadLine());
         return width;
      }   
   }
   
   class FindArea {
      static void Main(string[] args) {
         AreaDimension obj = new AreaDimension();
         obj.length = 4.5;
         Console.WriteLine(“Area = {0}”, (obj.length)*(obj.GetWidth()));
         Console.ReadLine();
    }      
  }
}

Discussion

Ask a question, share your thoughts or report an error.

2 comments

  1. After reading your article, I learned many new things about planning adventures abroad. I want to express my gratitude for sharing your travel knowledge and experience with us. We discussed a similar topic on TravelForums. Keep up the amazing work!

  2. Howdy, i read your blog occasionally and
    i own a similar one and i was just curious if you get a lot of spam
    feedback? If so how do you reduce it, any plugin or anything you can advise?
    I get so much lately it’s driving me crazy so any assistance is very much appreciated.!

Sign in to participate in the discussion.

Join the discussion