C# 3.0 Orcas Language Features - Automatic Properties

by UnquaLe 1. October 2007 21: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: ,