Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool



Automatic Properties, where have you been for the last 8 years????

With the recent release of .Net 3.5 one of the new features they added is Automatic Properties.

Automatic Properties allow you to NOT need to create an instance variable for your properties (assuming you only need simply getter/setter functionality), the compiler will do it for you.

Here is a simple example:

public string SomeProperty { get; set; }

Anyway, I have been using .Net 3.5 exclusively for the past few weeks and I have just fallen in love with Automatic Properties.  God I wish this would have been added a LONG TIME AGO..... Oh well

And before anyone says anything, public member variables are NOT the same.

Till next time,

P.S. I have been coding for the past 8 years, I know that .Net has not been out that long.
 


Published Mar 21 2008, 08:28 PM by Derik Whittaker
Filed under:

Comments

Derik Whittaker said:

@Keith

Simple.  You cannot do this with member variables

public string SomeProperty { get; private set; }

# March 22, 2008 9:34 PM

Jarle Nygård said:

There are few other differences as well, since the auto properties can easily be expanded to "old style" properties; this means that you can alter on add some sort of logic/logging/validation/etc behind the props. This is not possible if you're using fields.

# March 24, 2008 9:35 AM

Alexander Kojevnikov said:

Derik,

Both var and the automatic properties are C# 3.0 compiler features. They are not part of .NET 3.5, you can use them for .NET 2.0/3.0 projects too.

# April 14, 2008 9:45 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Derik Whittaker

Derik is a .Net Developer/Architect specializing in WinForms working out the northern suburbs of Chicago. He is also believer and advocate for Agile development including SCRUM, TDD, CI, etc.

When Derik is not writing code he can be found spending time with his wife and young son, climbing on his bouldering wall, watching sports (mostly baseball), and generally vegging out. Check out Devlicio.us!

Our Sponsors

Proudly Partnered With


This Blog

Syndication

News