ttmind

Main Navigation

ttmind
  • jim-jams
  • Tech
  • Positive
Login

Login

Facebook Google

OR

Remember me Forgot password?

Don't have account? Signup here.

Sort by Categorys

.Net

PHP

Java

JavaScript

Database

Server

Client Side

Tools

Artificial Intelligence

Cloud

Hybrid Development

Event

Smart City

Education

Security

Scrum

Digital Marketing

APP Development

Business

Internet

Simulation

Art

Network

Microservices

Architecture

Technology

Leadership

    Top Articles

  • How Does Social Media Bring People Together?
    TTMind Author
  • How to read appSettings JSON from Class Library in ASP.NET Core
    Anil Shrestha
  • Printing Support In Asp.Net Core
    TTMind Author
  • HOW TO EXTRACT TEXT FROM IMAGE USING JAVASCRIPT (OCR with Tesseract.js)?
    Prakash Pokhrel
  • Images Upload REST API using ASP.NET Core
    Prakash Pokhrel
  • Related Topic

  • How to read appSettings JSON from Class Library in ASP.NET Core
  • Printing Support In Asp.Net Core
  • Images Upload REST API using ASP.NET Core
  • How to use IActionFilter, IAsyncActionFilter in ASP.NET Core MVC?
  • ASP.NET CORE - Blazor CRUD operation using ADO.NET
  • Tech
  • About Us
  • Contact Us
  • TechHelp
  • PositiveHelp
  • Jim-Jams Help
  • Terms & Conditions

© Copyright ttmind.com

Main Content

C# 8.0 most awaited Features

.Net C# about 7 years ago || 12/5/2018 || 2.7 K View

  • Hide

 

One of the most loved and popular programming language of the present time. With the new arrival of C# coming nearer and nearer we all are pretty much excited about the major release of C# Version 8. C# has been around for three decades and  it is expected to release it’s latest version in 2019 and everyone is curious about the new features that it will carry.

Looking back at the history, every new release of C# has coupled up with new version of Visual Studio and .Net runtime.  With the release of C# 7.2 and 7.3 now it’s time for C# 8,0which will soon make it to our doorsteps. We can say that it is coming with cool features which will come alive with Visual Studio 2019. But, We already have  a slight information about what we can wait for in the new version. Some of the other improvements will tickle out in the coming days.

The motto of this article is to provide you with an overview of what to expect from C# 8.0 :

Nullable Reference Types:

This feature will help to prevent the null reference exceptions that have  bothered developers for many years.

It prevents you from putting null into ordinary reference types .

But there can be a situation where you need a nullable reference type, such as string. In such case the new thing would be nullable types.

The same syntax i.e. question mark will be used for nullable reference type.

For eg:  string? s = null; // Ok

Async Streams:

The previous version of C# was not helpful if you wanted to produce or consume continuous streams of data. Like you could get from IoT device or cloud service.

Async Streams will provide an abstraction that is an asynchronous version of IEnumerable.  i.e IAsyncEnumerable<T>

For Example:

async IAsyncEnumerable<int> GetBigResultsAsync()
{
    await foreach (var item in GetResultsAsync())
    {
        if (result > 10) yield return result; 
    }
}

 

Default Implementations of Interface Members:

Now it will be easier to work with Interface. In the present you can’t add members to Interface without breaking source or binary compatibility. But now if someone doesn’t implement the member, the developer will get default implementation instead. This type of feature is already available in programming language like java.
 

For Example:

interface ILogger
{
    void Log(LogLevel level, string message);

    void Log(Exception ex) => Log(LogLevel.Error, ex.ToString()); // New overload
}
class ConsoleLogger : ILogger

{
    public void Log(LogLevel level, string message) { ... }

    // Log(Exception) gets default implementation
}

Light Weight Classes(Records):

Another great feature of C# 8 is a way to create a C# class called records.These are light weight classes that is collection of fields.

It heps in the fast creation of object and also for the comparison of objects.

For Example:

Creating a simple Student class would look like:

Class Student { int ID, string name, string department }

It will be expanded into a larger class implementing IEquatable.

 Recursive Patterns:

Recursive patterns are the type of patterns that can contain other patterns.The new version of C# will allow recursive patterns.

IEnumerable<string> GetEnrollees()

{
    foreach (var p in People)
   {
        if (p is Student { Graduated: false, Name: string name }) yield return name;
   }
}

  

 

Switch Expressions with light version of switch statements:

Switch statements can be cumbersome to write. So the C# 8.0 will come up with light version of switch case where all cases are expressions.

For Example:

var area = figure switch

{
    Line _      => 0,
    Rectangle r => r.Width * r.Height,
    Circle c    => Math.PI * c.Radius * c.Radius,
    _           => throw new UnknownFigureException(figure)

};

 

Target Typed new Expressions:

When we are creating a new object, the type is already provided from the context. In such cases it will let us omit the type:

 This feature was introduced by one of the member of .NET community

For example:

Point[] ps = { new (1, 4), new (3,-2), new (9, 5) };             // all Points...................

 

Almost all the features of C# 8.0 will work on any version of .NET. But few of them can have platform dependencies like the Async streams, indexers and ranges all will depend on the new framework type  i.e. DotNet Standart 2.1 .

Also Read: Best Laptops for Programmers

  • 0
  • 0
  • 0
    • Facebook
    • Twitter
    • Google +
    • LinkedIn

About author

Binod  Bhandari

Binod Bhandari

Life is not just about thrieving but all about living.

Reset Your Password
Enter your email address that you used to register. We'll send you an email with your username and a link to reset your password.

Quick Survey