Skip to main content
New Features In C# 8.0

Expected New Features In C# 8.0

Recently in channel 9, Mads Torgersen demonstrated the first four features of C# 8. Below is the brief description of those new features in C# 8.0. This is going to be the next major release after C# 7.0

Expected New Features In C# 8.0

C# 8.0 Previewed: below are the 4 features which Mads discussed in his recent talk on channel 9.

1. Nullable Reference Types

With C# 8.0, references type would not be nullable by default. Assigning null to a non-nullable reference type will be a compiler warning, similarly reading from a nullable type would also be a compiler warning unless the variable in question was explicitly checked for null ahead of time.

2. Async Streams

Async streams are the asynchronous equivalent of IEnumerable. The syntax for the same is:

foreach await (string s in asyncStream)

3. Default Interface Implementations

A default interfaces programming capability, so interfaces can evolve via virtual extension methods. An API author could add methods to an interface in future versions without breaking source or binary compatibility. This feature already is available in programming languages such as Java.

For a detailed explanation refer –

Interface Method Implementation C# 8.0.

The most cited use case for this feature is the ability to add a Count property to IEnumerable<T>. The idea is that instead of using the Enumerable.Count extension method, developers can get Count for free and optionally override it if they can provide a more efficient alternative.

interface IEnumerable<T>
{
    int Count()
    {
        int count = 0;

        foreach (var x in this)
            count++;

        return count;
    }
}
interface IList<T> ...
{
    int Count { get; }
    override int IEnumerable<T>.Count() => this.Count;
}

4. Extension Everything

Extension properties were the long-time pending feature. 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 Student class you would write:

extension StudentExt extends Student {
    //methods and properties go here
}

In this video, Mads Torgersen talks about some of the planned features of C# 8.0.

For more information, you can refer C# Language Design Repo and the proposal section.

You can also refer to the list of C# features with respect to its versions:

List of C# features version by version

What do you think?

Dear Readers,
If you have any questions or suggestions please feel free to email us or put your thoughts as comments below. We would love to hear from you. If you found this post or article useful then please share along with your friends and help them to learn.

Happy Coding!

DotNetCrunch

DotNetCrunch is a popular blog for latest Microsoft® technologies which is aimed for beginners and intermediate level professionals.