Navigation


Upcoming courses:

  • Aarhus, Denmark, March 5 - 9, 2012
  • New York City, USA, March 26 - 30, 2012
Read more on our website

About me

Brian Holmgård Kristensen

Hi, I'm Brian. I'm a Danish guy primarily working with ASP.NET e-commerce solutions using Microsoft Commerce Server.

I'm co-founder and core-member of Aarhus .NET Usergroup (ANUG), which is a offline community for .NET developers in Denmark.

You can visit my View Brian Holmgård Kristensen's profile on LinkedIn or follow me on Twitter @brianh_dk. Also please feel free to contact me via e-mail Send me an e-mail.

Categories

On this page

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0

Send mail to the author(s) E-mail

Total Posts: 36
This Year: 0
This Month: 0
This Week: 0
Comments: 10

Sign In

Follow me on Twitter @brianh_dk
 Friday, 09 November 2007

I really had my doubts on whether I should attend this session, because a colleague of mine, Søren, already had done a presentation about the new language features in C# 3.0, and also I attended a session yesterday by Luca Bolognese on “The .NET Language Integrated Query Framework” where he covered many of the new features as well. However there was a really good reason for me being there; 1) that the session took place in the Auditorium where also my previous session on Silverlight went on, meaning I did not have to move at all, and 2) that I have a lot of interest in C# 3.0 and attending a session with only focusing on that simply could not be a bad thing for me.

This session was by Luke Hoban, Program Manager at Microsoft responsible for the C# compiler. Luke started out by telling about their design themes on this C# 3.0 version, which goes as:

1. Improve C# 2.0 – obvious as many might think.

2. Language Integrated Query (LINQ) - making querying a first class concept in the language. LINQ is really the driving force behind many of the new language features that we'll see as LINQ required making a lot of new capabilities in the language.

3. Being 100% backwards compatible which is always the case.

The rest of the session by Luke was pretty much purely demo-driven to show us the use of the new language features, covering:

Auto-Implemented Properties

The option to introduce a property with an implicit backend data variable. This is very useful for most properties in your classes as they usually always just simple properties without any logic.

Object Initializers

The option to set values on public properties of an object directly in its constructor.

Collection Initializers

Just as with Object Initializers this feature allows to add items to a collection object directly in its constructor.

Local variable type inference

This allows for any local variable inside the code, to just leave out the name of the object type and use the var keyword instead. This is syntactical very convenience and it is completely strong-typed as the compiler already knows which type you operate on given the right side of the assignment expression.

Note that you can't use var as return type or as parameter type. In level of public interface explicit specifying the types is the only way to go.

Query Expressions

The most important thing to understand about Query Expressions is that they are just like any other syntax in C#. It is not some sort of Domain Specific Language, it is just like e.g. a for-loop or a while-loop - a part of the C# language.

Two major reasons why Query Expressions are valuable: 1) they can be used not just over objects but all sorts of data; relational, XML, anything that implements the LINQ Query Provider and 2) it is easy to use as it is a very declarative way of writing queries.

Anonymous Types

The ability to create new shapes that suits the exact needs in your specific logic. Very useful for intermediate results.

The class will be auto generated by the compiler, making sure the type will have the right signature.

Also you can't return it – which means they are for most purposes constrained to a method body.

Lambda Expressions

A way to do anonymous methods but in a more efficient and declarative way. A Lambda Expression is indicated by the => (goes to) keyword. A Lambda Expression starts with a list of all parameters sent to the function.

Extension Methods

The ability to kind of virtually add new methods to existing objects that normally are out of your reach, e.g. sealed classes. It is important to note that this does not in any way break encapsulation. It is purely syntactic sugar. The compiler will go ahead and call the static method on the concrete extension class when it sees an Extension Method.

Expression trees

This is telling the compiler to capture Lambda Expressions not as delegates but as an actual Expression Tree which is a rich object model containing body and parameters exposing the Lambda Expressions thereby allowing the consumer to decide how to process this information, e.g. creating dynamic SQL as with LINQ To SQL.

Partial Methods

Allows you to write code that calls a method that may or not be defined and must be declared within a partial class. A common scenario for partial methods is lightweight event handling and in e.g. LINQ To SQL often used for doing validation in a custom partial class for the generated class.

Implicitly-Typed Arrays

This is a simple but helpful feature allowing you to declare a new array but leave out the name of the type. The compiler then does the type inference for you.

Example: var myArrayOfIntegers = new[] { 1, 2, 3, 4 };

It really was a great session by Luke Hoban and I am glad I attended even though I had my doubts. I feel very lucky having attended only good sessions so far!

Posted on Friday, 09 November 2007 08:25:16 (Romance Standard Time, UTC+01:00)
# | Comments [0]
Comments are closed.