Geeks With Blogs

News Awarded Microsoft MVP C#.NET - 2007, 2008 and 2009


I am born in Bangladesh and currently live in Melbourne, Australia. I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net)and born in Bangladesh.
I am founder and Chief Executive Officer of
Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Co-founder and core developer of Pageflakes www.pageflakes.com.
Simplexhub, is on its mission to build a smart virtual community in Bangladesh and recently launched beta realestatebazaar.com.bd an ASP.NET MVC application written in C#.NET.


Some of 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
Shahed Khan blog

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.

Posted on Wednesday, June 11, 2008 12:21 AM | Back to top


Comments on this post: C# 3.0 tips, Automatic Property

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Shahed Khan | Powered by: GeeksWithBlogs.net