Monday 13 April 2015

Encapsulation in C# dotnet



Hello Friends,                                                                                                                          
                 Now I am going to describe anther oop concept in C#.net i.e. Encapsulation.It  is a  Mechanism which is responsible to hide all internal part of an object  from outer world  and  It’s scope of access and visibility depends upon the access specifier.By using this technique  Data member and member function bind a single unit which leads to data security.
 RealWorldExample                                                                                                                                                                                         When we use computer keyboard for input data at that time we can’t know the internal process means  how it execute internally.
Ex:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace encapsulationprog
{
    class encaps
    {
        private int myencaps1;

        public int  myencaps
        {
            get
            {
                return myencaps1;
            }
            set
            {
                if (value > 0)
                  myencaps1 = value;
                  else
                   myencaps1 = 0;
            }

        }
        static void Main(string[] args)
        {
            encaps obj = new encaps();
            obj.myencaps =85;
            Console.WriteLine(obj.myencaps);
        }
    }

   
}

Thanks & Regard
Rabi Narayan

No comments:

Post a Comment