logo_CsharpThe guys from Microsoft seem to be working with lightning speed. At least when it comes to C# and the .Net framework.

Looks like C# 8.0 is at our doorstep and while it’s still early news it’s exciting nevertheless. In a recent channel Channel 9 video Mads Torgersen has demonstrated the first few features that we can expect.

 

Nullable Reference Types

The reference types would no longer be nullable by default. Instead, you would have to explicitly mark them as nullable using the same “Type?” syntax that you use for nullable value types.

Assigning a null to a non-nullable reference type will be a compiler warning. Likewise, reading from a nullable type would be a compiler warning unless the variable in question was explicitly checked for null ahead of time. So developers would need to put question marks where appropriate:

x?.MethodName();

Async Streams

Async streams(or foreach async) is a feature that has been talked about for a while now and we might finally get it in C# 8.0. The syntax is supposed to be:

foreach await (string s in asyncStream)

And when defining an async iterator, you would use this function signature:

async IAsyncEnumerable MethodName()

Default Interface Implementations

Default interface implementations are basically a (limited) form of multiple-inheritance. This will allow abstract interfaces to fully define methods just like abstract classes. However, abstract interfaces will still not be able to declare constructors or fields.

The primary benefit of default interface implementations is that you would be able to add new methods to an existing interface without breaking backwards compatibility (sort of, because this isn’t guaranteed, as it would only work when a suitable default method can be devised).

Extension Everything

So far we’ve only been able to add extension methods in static classes. With this new feature we would finally be able to define extension properties as well as well as not have to use static classes to define your extension methods(which was ‘sort of’ a complaint by many people).

Under the new design, there is a new top-level construct called an “extension”. For example, if you want to create extension methods and properties for a Customer class you would write:

extension ProductExt extends Product {
//methods and properties go here
}

In addition to properties, events, and operator overloads, they are even considering allowing extension constructors (could be very interesting in factory and object pooling scenarios).

 

More info

For more information, you can watch the Channel9 video with Mads Torgersen .

You can also follow the progress of the C# language design in the official C# language repo on GitHub.

‘Till next time…Happy coding.

/Bojan

Advertisements

Posted by TheBoyan

I have been programming since I was 11 years old (Yes, I'm one of those, for real). First programming language I learned was BASIC, on a Commodore64. Then around high-school it was C and Assembly. Just before and during university days it was C++. I started doing some professional work during this period, part of the reason why I dropped out of uni in my final year. I have never stopped since then. Going through a plethora of technologies ranging from C and Assembly languages, Delphi to C++, C#, Java and so on and so forth... trough 20 (and more, who counts, does it even matter) years of software development. I have not lost even a single bit of my ambition and love for the craft from those first young days, nor the energy...I absolutely love what I do. I like to get my hands into all aspects of software development. Now-a-days I use mainly Microsoft related technologies .NET C#, with a lot of database design/management usage of SQL server, but not in any way limited to that.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s