Encapsulation | Code2night.com
Code2night
  • Home
  • Blogs
  • Guest Posts
  • Tutorial
  • Post Blog
  • Register
  • Login
  1. Home
  2. Blogpost

Encapsulation

Date- Dec 09,2023

1432

Encapsulation

Encapsulation is used to protect the data from being accessed by outside.It is a process that binds together code and data which is manipulates according to requirement. Encapsulation means that covering up of data under a single unit.

  • For Using data where we declare variables as private. By following ways we use data without any damage or change.
  • For using the data in the class.we declare mutator(set method) and accessor(get method).
  • Encapsulation also used by properties.By using set accessor in the property implementation for accomplished write-only data.
  • By using get accessor in the property implementation for accomplished read-only data.

Advantages

  • It is used for data hiding.
  • It is used for Re-usability.
  • flexibility increased by encapsulation.

Example


using System; 
public class MyCode {
      
    private String EmployeeName;
    private int EmployeeId;
    
    public String Name
    {
          
        get
        {
            return EmployeeName;    
        }
          
        set 
        {
            EmployeeName = value;
        }
          
    }
      
    public int Id
    {
          
        get 
        {
            return EmployeeId;    
        }
          
        set 
        {
            EmployeeId = value;
        }
          
    }
      
}
  
public class Program {
      
    static public void Main()
    {
        MyCode obj = new MyCode();
        obj.Name = "Roy";
        obj.Id = 1;
        Console.WriteLine("Name: " + obj.Name);
        Console.WriteLine("Id: " + obj.Id);
    }
}

OUTPUT

Name: Roy
Id: 1

Comments

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1210
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2025 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier
  • Guest Posts