Orcas – First try

 After reading a post by Scott Guthrie on the new C# Orcas language features I decided to download Orcas and try them out.  (**excited**)

The new features I practiced with and love are:

  1. Object initializers
    Example:
    Prior to Orcas:

    Person person = new Person();
    person.FirstName = “Scott”;
    person.LastName = “Guthrie”;
    person.Age = 32;


    Orcas:

    Person person = new Person { FirstName=“Scott”, LastName=“Guthrie”, Age=32 };

    I personally like this because I like to have a constructor initializer for all my objects.  That is no longer necessary. =)

  2. Collection initilizers
    Orcas:

    List<Person> people = new List<Person>();

    people.Add( new Person { FirstName = “Scott”, LastName = “Guthrie”, Age = 32 } );
    people.Add( new Person { FirstName = “Bill”, LastName = “Gates”, Age = 50 } );
    people.Add( new Person { FirstName = “Susanne”, LastName = “Guthrie”, Age = 32 } );

    The new feature I played with that I’m still not to sure about is:

  3. Automatic Properties
    Example:
    Prior to Orcas:

    public class Person {

    private string _firstName;
    private string _lastName;
    private int _age;

    public string FirstName {

    get {
    return _firstName;
    }
    set {
    _firstName = value;
    }
    }

    public string LastName {

    get {
    return _lastName;
    }
    set {
    _lastName = value;
    }
    }

    public int Age {

    get {
    return _age;
    }
    set {
    _age = value;
    }
    }
    }

    Orcas:

    public class Person {
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age { get; set; }
    }

Guthrie’s post has links to Bart deSmart’s blog where he shows what happens under the covers for each of these features.

More to come.

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Jason Meridth

Continuously learning software developer trying to not let best be the enemy of better
This entry was posted in .NET. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

Comments are closed.