Auto Implemented Properties in c#

Before working any project you need to work on Architecture.At present there are so many architectures are present in .net.Those are one Tier,Two Tier,Three Tier and so on.Except in one and two tier the other Architectures we use this accessors.But implementation of accessors is different after .NetFramework 3.0 and greater versions. what are accesors and what's the difference between implementation of accessors before .NetFramework3.0 and after i want to discuss in this Article with code snippets

Object Oriented Programming has got several features incorporated in it.In that Encapsulation is one of the feature.


Encapsulation, in object oriented programming methodology, prevents access to implementation details.

How we implement Encapsulation in real time :

Now the above definition is Good.But we need to implement it practically.
In Three tier Architecture you see one Class Library and you are writing a class to get and set your members that class is nothing but Business Entity class that in short form we call it as BE that Properties enable a class to expose a public way of getting and setting values, while hiding implementation or verification code.

uses of Get and set Properties :

A get property accessor is used to return the property value

A set accessor is used to assign a new value. These accessors can have different access levels.

Now see the below snippet of Code Lines

public class BEChangePassword
private int _nId;
private DataSet _objDs;
private int _nUserId;
private string _strPwd;
private int _nStatus;
private int _nRepeatPwd;
private string _strNewPwd;

public int nRepeatPwd
get { return _nRepeatPwd; }
set { _nRepeatPwd = value; }
public int nId
get { return _nId; }
set { _nId = value; }
public int nUserId
get { return _nUserId; }
set { _nUserId = value; }

public DataSet objDs
get { return _objDs; }
set { _objDs = value; }

public string strPwd
get { return _strPwd; }
set { _strPwd = value ; }
public int nStatus
get { return _nStatus; }
set { _nStatus = value; }

public string strNewPwd
get { return _strNewPwd; }
set { _strNewPwd = value; }


The Private access specifiers are called member variables.This is for up to .NetFramework2.0.

Auto Implemented Properties:

But .NetFramework 3.0 and later there are auto implemented properties.

See the below snippet of Code lines.

public class BEMoInbox
public string strSHORTCODE{get; set;}
public string FromRECDDATE { get;set;}
public string ToRECDDATE { get; set; }
public int nRetVal { get; set; }
public int nReccnt { get;set; }
public int nCustomerId { get; set; }
public int nCreatedBy { get; set; }
public string strSCodes { get; set; }

In auto implemented Properties The number of Variable declarations and also the No. of code lines has drastically reduced.If you still not able believe it So try the above code Your self by putting in your Business Entity class Library.

Article by srirama
A Good advice from parent to a Child , Master to a Student , Scholar to an Ignorant is like a doctor prescribed pill it is bitter to take but when they take it will do all good for them --- Bhushan

Follow srirama or read 74 articles authored by srirama


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: