LINQ in Norway
PDC2008 - Type System Changes with CLR 4.0

PDC 2008 - C# Futures

Again, Anders Hejlsberg had a great session at #pdc2008. This time about C# 4.0 and C# 5.0!

C# 1.0 was the core about OO, C# 2.0 added generics. With C# 3.0 is the first version with new language features - LINQ, and this is expands with the future versions. C# is a multi-paradigm language. Of course, it's an OO language (since 1.0), since 3.0 it can also be used as functional language. The main areas of enhancements are in these areas:

  • declarative
  • dynamic
  • concurrent

Microsoft is doing a shift in regard to C# and VB to recognize reality. Features from C# are brought into VB, and features from VB into C# - because the demand is here!

C# 4.0 adds dynamic programming. With this it is easy to call not only .NET objects but also easily COM objects, JavaScript, Python...
The enhancements can be grouped into these areas:

  • dynamic keyword
  • optional and named parameters
  • co- and contra variance

With the new dynamic keyword, a variable can be declared in C# that references a object that is created during runtime, e.g. from COM or JavaScript.

dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);
Every method that is invoked on a dynamic object returns a dynamic result that is dynamically cast to the type the return variable is declared (e.g. an int in the example). A great feature here is the syntax looks the same, no matter if the calculator is a COM object, JavaScript, Python or Ruby. Binders for each of these variants are available, and custom binders can be written as well.
Using C# it is also possible to create dynamic runtime-objects by implementing the interface IDynamicObject or deriving from the base class DynamicObject.

A many times requested feature that is available with C# 4.0 is optional and named parameters. Instead of defining several overloads, optional parameters can be defined:

StreamReader OpenTextFile(
   string path,
   Encoding encoding = null,
   bool detectEncoding = true,
   int bufferSize = 1024);
this can be called wih only the mandatory parameter:
and also with named arguments:
OpenTextfile("foo.txt", bufferSize : 4096);
Of course, named arguments must be after the mandatory parameters.

Optional and named parameters have a great COM Interop story. No more ref missing parameters. "It took 10 years to get back where we were".

Covariance and contra-variance is another new feature. co-variance or contra-variance information can be added to generics, e.g. and . means that T can be used only in output positions, only in input positions. Existing interfaces and delegates such as IEnumerably and IComparable are changed to the new notation. A blog entry with samples about this feature follows here!

Anders also demonstrated C# 5.0 features. C# 5.0 opens up the compiler to offer modern ways for meta-programming - compiler as a service!

More information about C# futures:



Feed You can follow this conversation by subscribing to the comment feed for this post.

jordan 11

Sales of the products in the world, is not the first car, but himself. In you successfully sells oneself to others, you must have 100% sells oneself to yourself.

supra shoes

Agree with your point of view

coach factory stores

Yeah, you're right.*

christian louboutin shoes

Every great achievement was a dream before it become a reality.

UGG Shoes

i love you post

Air Jordan

Tomorrow is an other day!@

christian louboutin shoes

*Perhaps you should go on a tour.

air jordan

That's not his. Steve's is black*_*

air jordan

I can imagine TONS of uses for this*_*

cheap supra shoes

Is necessary to hope. . . for hope itself is happiness! china

yes..another great post...really interesting read.

Air Jordan 21

Show them how much they mean to you and seize this opportunity before life has you in the fast and furious dating lane again.

supra vaider shoes

Love those! I enjoy following your posts on facebook and rss!

mulberry handbags

I like ANMJ on FB & just subscribed to the email feed! :)

Monster LadyGaga

The composition of very good. Give me a lot of help, gave me a big inspiration! Hope to continue trying to write something better!

The comments to this entry are closed.