posts - 216, comments - 198, trackbacks - 68

My Links

News




I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net) and born in Bangladesh.
I work for Ocean Informatics Pty Ltd as a Senior Developer - Analyst.
I am also co-founder and core developer of Pageflakes www.pageflakes.com
and most recently created SmartCodeGenerator

My Articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Smart Code Generator .NET: Usage Overview
Smart Code Generator .NET: Architectural Overview
Smart Code Generator .NET: using with NAnt and Cassini

Archives

Free Programming Language Training

C# 3.0 tips, Automatic Property

Declaring a property in C# 3.0 is super easy and super short.

public class Student
{
  public string Name {  get; set; }
}

yes that's it, the framework will take care of the rest, the private variables will be automatically created and the getter and setter will be automatically implemented.

Here is how we can assign value to an automatic property via the constructor

public class Student
{
    public string Name {  get; set; }
    public Student (string name)
    {

       this.Name = name;

    } 
}

And finally, here is how we can declare a Readonly property

public class Student

     public string Name {  get; private set; }  

   public Student (string name)
   {

     this.Name = name;

   } 
}

Hope this helps, Enjoy coding.

Print | posted on Wednesday, June 11, 2008 12:21 AM |


Feedback

No comments posted yet.


Post Comment

Title  
Name  
Email
Url
Comment   
Please add 3 and 2 and type the answer here:

Powered by: