New stuff in C# 4.0
I’m just prepering for a presentation of new features in VS 2010 and .NET Framework 4.0, so let me give you just a little sneak peak into new cool features of C# 4.0:
dynamic type
Very short said, it’s something like var in script languages. But let me give you a simple example:
dynamic test = new MyObject();
and even MyObject doesn’t have method (for example) called DoSomenthing(), you can write:
test.DoSomething();
and compiler will compaile with no errors. You would just get an runtime exception, saing that object doesnt have that method.
In real world that can be used for example in looping through some array, wich is defined like object, but you know, that you have in array only strings.
optional parameters
This is best explained through simple example, where I have one method, defined like this:
void DoSomething(int x, int y, int z=5) { … }
And when calling this method, i can leve out z parameter (it will take the default value defined in method) like this:
this.DoSomething(5,3);
And it’s even better – you can mix parameters in calling functions and define parameters by its name:
this.DoSomething(y:3,x:5);
There are some more cool features, especially about Office developement, but you can find that information on the web :) .
I hope you get the picture – more info you can find in this cool video or this blog post where you’ll find some links about other cool fetures in C# 4.0.