Coded - Web Development and Programming Blog

C#, ASP.NET, Google, Remoting, AJAX, Silverlight, Web Development

Cool new C# 3.0 syntactic sugar

Posted in .NET Framework, C# by Andrei Alecu on the September 21st, 2007

I was recently reading a post on MSDN blogs by Abhinaba Basu about a new feature in C# 3.0 and Visual Studio 2008 (Orcas)—Automatic Properties.

Coming from a Visual Basic background, I never really understood why C# forces you to do some things the hard way, even when it knows by itself what you meant to do, and it could have done it for you in the first place.

Anyways, back to Automatic Properties

With C# 3.0 you can now code a property as easy as:

public int Property { get; set; }

This is what you would want 99% of the time. The old way of having to declare a private variable for each of your properties was really hurting code readability if you had lots of properties.

The compiler still generates the private variable, but at least you don’t have to see it in your code. For more information about what happens behind the scenes, see this blog post by Abhinaba.

I’m pretty glad with this feature because I’m using properties extensively in my projects, and it’s one of those new features that I can easily see myself using right from the start.

Technorati Tags: , , , ,

Bookmark on del.icio.us

Leave a Reply