DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. JavaScript
  4. What’s new in C# 5.0 and VB.Net?

What’s new in C# 5.0 and VB.Net?

Samuel Jack user avatar by
Samuel Jack
·
Aug. 11, 12 · Interview
Like (0)
Save
Tweet
Share
7.96K Views

Join the DZone community and get the full member experience.

Join For Free

Anders Hejlberg layed out what’s new in C# 5.0 and VB.Net a while back. Bear in mind that Microsoft now have a policy of language parity for C# and VB.Net. So both languages get Windows Runtime support, Asynchronous programming and a brand new feature, Caller info attributes. VB.Net plays catch-up, and finally gets support for Iterators.

Asynchronous Methods

The first demo in Anders talk was about asynchronous programming. He introduced it by reminding us how vital responsiveness is in touch applications. This was something Jensen Harris mentioned in his talk. Touch User Interfaces are visceral. If an application doesn’t respond immediately when you touch it, it feels dead, whereas using a mouse or keyboard introduces a kind of disconnect between you and the computer which makes delays feel more acceptable.

In the Windows Runtime, the designers took the decision that if an operation was going to take more than 50 milliseconds to complete, it must be implemented asynchronously. There will be no synchronous equivalent – it would make it too easy for developers to do the lazy thing. So, all of a sudden it becomes really important to be able to do asynchronous programming easily.

This is where C# shines in comparison to C++ or Javascript for writing Metro style apps. In those languages, doing asynchronous programming means callbacks, and that means turning your programming inside out. The Asynchronous Methods feature in C# allows you to do async programming in the usual, straightforward, do-this-then-that fashion.

I won’t say any more on that here. Go watch Anders demo if you haven’t groked async yet. Your future as a Windows developer depends on it!

Windows Runtime integration

In the next section of his talk (starting at 26:00), Anders demonstrated more of the deep integration that C# and .Net now has with the Windows Runtime. He showed how it is possible to take a C# “compute engine” and expose it to a HTML/Javascript meto-style app (it works just as well with C++). You can take a C# project, compile to a WinMD file, then reference it from your HTML/Javascript project. This gives you intellisense for your C# objects when you access them from your Javascript code. As Anders said, “In Javascript, you sometimes get lucky. [Beat]. Of course, in C# you get lucky always! … I’m Just saying!”

Caller Info Attributes

The aforementioned Caller info attributes came up next (see video at 32:00). Not a big feature, just a palate cleanser between demos, according to Anders.

Apparently the C# team often get asked when they’re going to introduce support for __FILE__ and __LINE__ macros, which, C++ developers will know, expand when compiled to produce a string containing the name of the current source file, and the current line, respectively. Of course, C# will only introduce support for macros over Ander’s dead body, so the team had to find another way.

Anders related that back in the days of C# 1.0 they had a design that implemented this feature using attributes, but it involved optional parameters on methods which weren’t supported at the time. Well, now C# 4.0 supports optional parameters on methods, so the team revisited the design, and, lo and behold, C# 5.0 now has the CallerFilePath, CallerLineNumber and CallerMemberName attributes.

You can write a Trace.WriteLine method like this:

public static class Trace
{
    public static void WriteLine(string message,
        [CallerFilePath] string file = "",
        [CallerLineNumber] in line = 0,
        [CallerMemberName] string member = "")
    {
        var s = string.Format("{0}:{1} - {2}: {3}", file, line, member, message);
        Console.WriteLine(s);
    }
}

Then, if you were to call Trace.WriteLine(“Something just happened”) the compiler would automatically fill out the optional parameters in the WriteLine method with details of where you made the call from.

This isn’t in the current developer preview, but will be in the final release. As Anders said, not a big feature, but no doubt somebody will put it to good use.

The Roslyn (Compiler APIs) Project

The last half of the talk (starting at 35:26) dealt with what comes after C# 5.0, which is what project “Roslyn” in all about (named apparently after a cute little mining town, an hours drive from Seattle). Roslyn is “the compiler re-imagined”. Anders introduced Roslyn by noting that we are increasingly addicted to IDE productivity tools which provide features like “Find Reference”, “Go to Symbol”, “Rename”,  and “Extract Method”. All these need knowledge about code that is traditionally locked inside the compiler.

Roslyn is all about building compiler APIs that expose what the compiler knows about code to the IDE and to developers. It will include Syntax Tree APIs, Symbol APIs, Binding and Flow Analysis APIs and Emit APIs. The APIs are designed using modern principles. So, for example, the SyntaxTree objects are completely immutable (though you can create new ones by combing bits from old ones) and this means that they are concurrency safe. All the language services in the IDE (syntax colouring, intellisense, etc.) are going to be using Roslyn.

All this is going to be available to us starting mid October, when a CTP of Visual Studio Roslyn will be released. APIs will be available for both C# and VB.

The demos Anders gave of Roslyn are pretty impressive (starting 43:00). First up was the ScriptEngine API that allows you to parse and execute code from a string, or even get a delegate back for executing it at some later point. This led in to the demo of the C# interactive window, which will be part of Visual Studio in the future. You can select code in the editor, press Alt-Enter and have it immediately executed in the interactive window. If you then go and edit it there, you get intellisense, even for methods that you have just interactively defined.

Another demo,roundly applauded, was “Paste as VB” and “Paste as C#” which uses the Roslyn APIs to parse and translate code from the Clipboard buffer. The source code for this will be made available in the CTP.

None of this was big news, of course, because Anders first started talking about it when I was at PDC in 2008. But it’s nice to know that it’s moving on steadily, and that we’ll soon be able to have a play with it.


dev Attribute (computing) app application JavaScript Integrated development environment teams Strings

Published at DZone with permission of Samuel Jack, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Is a Kubernetes CI/CD Pipeline?
  • Bye Bye, Regular Dev [Comic]
  • 7 Awesome Libraries for Java Unit and Integration Testing
  • How to Create a Real-Time Scalable Streaming App Using Apache NiFi, Apache Pulsar, and Apache Flink SQL

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: