July 28. 2007

First experience with Visual Studio 2008

Saturday, 28 July 2007

Posted by Sébastien Lachance with Comments (0)

Edit : This is actually some features of the new C# 3.0 compiler.

Yesterday I've downloaded the Beta 2 of Visual Studio 2008 and .NET 3.5. And I decided to start writing a little journal application. During the first hour I had not seen anything new and really started wondering what were the advantages of migrating to 2008 if you are not doing Web Application (new features concerning CSS, JavaScript, debugging, etc..). I decided to do a quick search on Google, and found the ScottGu's Blog (highly recommended) which was enumerating some new features. And found 2 that was directly applicable now to my application : Automatic Properties and Query Syntax. Automatic Properties. Suppose you are writing properties for a class. Don't you find that you are creating private field for nothing. Wouldn't it be simpler that the compiler generate it automatically for you. Check this out :

public DateTime? EntryDate
{
   get { return _entryDate; }
   set { _entryDate = value; }
}

become

public DateTime? EntryDate { get; set; }

Less code means more time to do something else, so I'm happy! And what about  Query Syntax? I had a collection of JournalEntry instance and wanted to find the instance containing the date the user selected. The way I had done it at first was to iterate through the collection and check if the date was the same (I could have done it with predicate too). But the way LINQ handle it was too cool not to try it. P.S One advice before you try this. Make sure the project is compiled using .NET 3.5 and you reference System.Core. My little loop has became this :

IEnumerable<JournalEntry> results = from j in Journal
                                    where j.EntryDate == selectedDate
                                    select j;