Automatic Properties

by mgordon 14. November 2007 08:20

I've been exploring some of the new language features that will be available in the coming version of .Net.  I continue to see things that look like they have been borrowed from dynamic languages.  Another to add to the list is automatic properties.  In C#, you'll be able to define properties like this.

public string FirstName { get; set;}

This is functionally equivalent to the following:

private string _FirstName;
public string FirstName
{
    get
    {
        return _FirstName;
    }
    set
    {
        _FirstName = value;
    }
}

This will be a real timesaver for those not using a tool such as CodeRush where creating he above block of code is reduced to three keystrokes (ps<space>) and then typing in the name of the property. 

Now, look at how the equivalent is accomplished in Ruby.

attr_accessor: FirstName

Instead of specifying get; and set;, you specify attr_writer for a write-only property and attr_reader for read-only.

Tags: , , ,

General | .Net | Productivity | Ruby

Comments

9/1/2009 4:07:01 PM #

Couldn't say it better myself, keep up the good work mate! Smile

where to buy salvia in stores United States

9/14/2009 12:05:08 AM #

Wow! what an idea ! What a concept ! Beautiful .. Amazing � Smile

bad credit loans United States

9/14/2009 12:05:15 AM #

You made some good points there. I did a search on the topic and found most people will agree with your blog.

bad credit loans United States

Comments are closed

Powered by BlogEngine.NET 1.5.0.7
Theme by Extensive SEO