C# 4.0 + Visual Studio 2010 Beta + Windows 7 RC

Here we are with the Visual Studio 2010 Beta installed on Windows 7 RC, the most coolest and latest stuff out yet 🙂

In this post, I wanted to share some glimpse at Visual Studio 2010 beta along with some demonstration of one of the feature of C# 4.0 🙂 For Windows 7, I will write another detail post about the new features and what I like most and why it can be the best windows till yet!

So, coming back to VS 2010, If you start Visual Studio 2010 Beta, you will notice a major change in UI of Visual Studio with a nice, interactive and customizable startup page :

VS 2010 Beta Start up

Yes, It’s UI is built on Windows Presentation Foundation (WPF). So let’s go ahead and create a new project:

As you can see we have a similar kind of option, as in VS 2008, is available to select target framework version which is by default 4.0 🙂 and as you can see we have Silverlight templates available so now no need to install separate Silverlight 2 tools for VS :). Let’s move forward and create a new C# Console Application:

You will notice that editor itself is in WPF along with the intellisense menu but works almost as identical. So let’s try one of the feature of C# 4.0 🙂

I’m going to implement a method that takes dynamic typed object and that object will invoke a method which will be resolved at runtime!

DemoCSharpFeature

Didn’t get? Keep reading 🙂 Here we have a DemoCSharpFeature class that have a static method having a dynamic parameter “obj”. Now inside that method, I have written obj.ABC() which can be resolved only at runtime because at compile time, compiler does not know what will be the actual type and it will be resolved dynamically at runtime and hence compiler will not raise a compile time error here 🙂

I have created another DemoClass which have method ABC.

Main Method 

As you have noticed that I have created an object of DemoClass which contains method “ABC” and passed to CheckDynamicParameter. The demoObj parameter will be resolved at runtime and it will find ABC method in it. Thanks to dynamic type in C# 4.0, otherwise I would have used Reflection here or static typed object 🙂

Let’s hit F5!

image

The beauty is that even if I remove method ABC from DemoClass, the program will still compile because it will expect that when dynamic is resolved at runtime it will find the method ABC and if not found, a Runtime Binder Exception would raised.

That’s all for today! If you want to download Visual Studio 2010 Beta, visit Visual Studio on MSDN