Thursday at Windows Build Anders Hejlsberg presented the future directions of C#. The new version number of C# is 5. The major features on this version are the integration of the Windows Runtime (WinRT) and of course the already well known async and await keywords for asynchronous programming. Anders also talked about some other cool features that I’ll introduce here.
The preview of the async features for C# v5 are out for some time now. I’ve already shown these keywords in a blog article from last year. Deeper information on this will follow in upcoming blog articles. Anders also talked about some other cool features that I’ll introduce here.
Great news at the conference is that the WinRT API offers async versions of the API if the function needs more than 15ms. This are 10-15% of the methods of the API. These APIs only offer async versions. Functionality like file I/O, network I/O…
And async methods have a big place in the .NET Framework as well. This makes it a lot easier to write async applications. And all applications should use this! The user interface must be very very responsive.
The Windows Runtime is written natively. It’s a new version of COM. Using namespaces, classes, constructors, statics, events… Using it from C# feels very natural. Although it’s implemented natively it nearly cannot be differentiated from C# calling into managed methods. The Windows Runtime team took a lot of features from .NET and added it to the native Windows API.
Caller Info Attributes
C++ allows changing the code line numbers and filenames with __LINE__ and __FILE__ macros. Macros are not possible in C# and never will be. However, this feature now made it into C# by using optional parameters. The attributes CallerFilePath, CallerLineNumber, and CallerMembername can be used with optional parameters. Thus it’s easy to change the line numbers like in C++ but without Macros.
Compiler as a Service – Codename Roslyn
Looking more into the future of C#, Anders introduced the current state of compiler as a service. Scenarios that are possible with this are meta-programming, read-eval-print loops, DSL embedding, accessing the complete language object model…
Anders showed how to copy C# code and paste it as Visual Basic, and the other way around. Refactoring a data class by implementing INotifyPropertyChanged to extend the properties automatically. A C# interactive Window where code can be added on the fly including intellisense and refactoring features.
I think this to be a big changer in the features available within Visual Studio and expect a lot of extensions not only from Microsoft but also coming from the community.
A CTP will be available In four weeks from now.