.NET Evolved

By Paul Kiddie, Microsoft Student Partner

This year has been a great year for developers with the general release of the .NET Framework 3.0 that provides a new set of APIs to produce visually stunning client applications with the Windows Presentation Foundation (WPF), create distributed applications with the Windows Communication Foundation (WCF) and design and manage long-running, interconnected processes with the Windows Workflow Foundation (WF).

Even with this major milestone, Microsoft have been hard at work evolving tools with an impending release of a new version of Visual Studio codenamed “Orcas” and a new version of the .NET framework.

Orcas brings many new features to Visual Studio, notably new visual designers for WPF and WF, and allowing easy integration of WCF features into .NET applications. The .NET Framework 3.5 which will ship with Orcas brings a collection of new language features to both VB and C# which we will overview in this article.

First and foremost, there are significant changes to the syntax, including the following:

  • variables used do not need to given a type, as the compiler infers from the assignment what type it should be.  For example:
         string s = “Hello world” can be written as
         var s = “Hello world”
  • Rather than writing multiple constructors to instance an object, C# 3.0 allows developers to set public/protected fields in any type when instancing an object. For example, if we have a person structure with two properties, Name and Age, we can write:
         var person = new Person {Name=”Paul”, Age = 23};
    This has the side effect of also making the code more readable!
  • Lambda expressions. These allow developers to simplify code that requires expressions, such as the following, which returns a list of Persons over 18.
         List<Person> personsOver18 = persons.FindAll(delegate(Person p)
    {

              return p.Age>18;
         });
    Instead, we can now write:
         var personsOver18 = persons.FindAll(p => p.Age>18);

Finally, one of the most important additions is Language Integrated Query (LINQ). This allows us to perform SQL database-like operations such as from, select, where and orderby on any data source that implements IEnumerable<T> from within code. The aim is to unify queries done over a multitude of data sources including XML, database or standard CLR collections such as the List.

So as well as reducing the amount of code necessary which means less debugging, these advances bring some exciting changes. They give C# and VB properties of functional programming languages. Also, applications written to take advantage of the new features of .NET 3.5 will still work with the .NET 2.0 runtime.

For more information go to:

https://msdn2.microsoft.com/en-us/vcsharp/aa336745.aspx - Visual C# 3.0 language specification and short nugget videos outlining features of C# 3.0
https://msdn2.microsoft.com/en-us/netframework/aa904594.aspx - the LINQ project homepage