Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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.
 


Posted 03-21-2008 8:28 PM by Derik Whittaker
Filed under:

[Advertisement]

Comments

keith wrote re: Automatic Properties, where have you been for the last 8 years????
on 03-22-2008 6:02 PM

so how exactly are they different from member variables?

Derik Whittaker wrote re: Automatic Properties, where have you been for the last 8 years????
on 03-22-2008 9:34 PM

@Keith

Simple.  You cannot do this with member variables

public string SomeProperty { get; private set; }

Jarle Nygård wrote re: Automatic Properties, where have you been for the last 8 years????
on 03-24-2008 9:35 AM

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.

Alexander Kojevnikov wrote re: Automatic Properties, where have you been for the last 8 years????
on 04-14-2008 9:45 AM

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.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)