Resources » Code Snippets » C# Syntax

C# Automatic Properties


Posted Date:     Category: C# Syntax    
Author: Member Level: Gold    Points: 10


C# Automatic Properties - a new feature that's added to C# 3.0



 


In C# 3.0 and later, auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. They also enable client code to create objects. When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field that can only be accessed through the property's get and set accessors.


Auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors.

Earlier methods



public class Employee
{
string _empFname;
string _empLname;

public string EmpFirstName
{
get { return _empFname; }
set { _empFname = value; }
}

public string EmplastName
{
get { return _empLname;}
set { _empLname = value; }
}

}


when implementing automatic properties

public class Employee
{
public string EmpFirstName{ get; set; }
public string EmplastName{ get; set; }
}





Did you like this resource? Share it with your friends and show your love!


Responses to "C# Automatic Properties"

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

Feedbacks      

Post 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Using keyword
    Previous Resource: How to use Camera Dialog in windows mobile.
    Return to Resources
    Post New Resource
    Category: C# Syntax


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Get  .  Set  .  
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.