C# 3.0 Orcas Language Features - Automatic Properties

by UnquaLe 1. October 2007 14:42

If you are developer you are probably quite used to writing classes with properties.

public class Customer
{
    private string firstname;
    public string Firstname
    {
        get { return firstname; }
        set { firstname = value; }
     }
}

 

This is a simple property and there is no logic in the getter and setter of the property. With new coming up C# 3.0 compiler provides short way to use properties with Automatic Properties feature.

When you are using C# 3.0 you can make your classes more concise, For example;

public class Customer
{
    public string Firstname { get; set; }
}

 

Yeah ! I know its cool to write a property in a line ;)

C# 3.0 Compiler will automaticly generate private fields in your class and implement a public getter / setter property implementation to it.

Bart De Smet has a great write-up on what happens under the covers when using automatic properties with the March CTP release of "Orcas".  You can read his excellent blog post on it here.

Tags: ,

Development

Comments

2/19/2010 8:06:38 AM #

Betsey Ovit

I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites site list and will be checking back soon. Please check out my site as well and let me know what you think.

Betsey Ovit United States | Reply

2/19/2010 8:03:23 PM #

Fawn Tastet

This is a very important post, I was looking for this info. Just so you know I located your blog when I was researching for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.

Fawn Tastet United States | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen