Skip to content

All You Need To Know About C# 8.0

Nishtha Singh edited this page Feb 28, 2018 · 5 revisions

Originally released in 2000, Finally, C# has reached its third decade of life. The language has literally grown and changed across 7 major versions. Started off as Microsoft’s response to Java, the late-teen has introduced more innovations in a very short span than ever before. Microsoft team just released C# 8.0 featuring nullable reference types to improve code quality, in the accordance with the latest roadmap for the programming language. By the term nullable reference type, we mean developers would be provided some help when it comes to preventing null reference exceptions.

Being a C# developer, here are a few things that one must know before building a desktop or windows apps.

  • Data Structure & algorithms- These are alphabets of programming. Of course, you can skip this but it is very import ant for you as a programmer to get exposed to data structures and algorithms for long-term success.

  • Databases- SQL Server is the most commonly used Relational Database Management System (DBMS) amongst C# development companies across the globe. So make sure that you are pretty familiar with the basics that include how to create tables, views and stored procedures in SQL Server.

  • O/RMs (Entity Framework) - While using a relational database, we often end up using Object/Relational Mapper (O/RM) to save or load objects in a database. Right from Entity Framework, nHibernate, Dapper, PetaPoco, etc, you will come across several O/RMs but entity is the most commonly used among all.

What’s new in C# 8?

1. Non-Nullable & Nullable Reference Types

Primitives and reference types are the two variables mostly used in C# development. Primitives are the likes of int, char and double which cannot take on the value of null whereas reference types (any object such as string) have always been able to take on a null value and have null as the default.

With C# 8, there will be a project level setting to enable validation of nullable references. Code such as

String s = null;

Console.Write(s);

Will cause a warning because String cannot take on a value of null. Instead the code

String? s = null;

Console.Write(s);

Moreover, this code would also throw a warning because of Console.

2. New Lightweight Classes: Records

My favorite, records help to create POCO type objects and also solve a key problem around comparing equality between objects. For example:

Creating a record type for a bank account might look like

class BankAccount(Guid Id, string Name, decimal Balance)

I personally find it a nice shorthand way to create simple classes.

3. Default Interface Implementations

Being a developer, versioning interface can be a bit annoying because it requires that new method on the interface to be implemented on all the objects which implement the interface. Default interface implementations allow specifying an implementation in the interface so long as it is implemented as a function of existing methods on the interface.

Other new C# 8 features include:

  • Improved Extension Support- Ability to use more than just extension methods
  • Async Streams- Capable enough to have enumerators that support async operations. Including new IAsyncEnumerable and IAsyncEnumerator interfaces.
  • Async Disposable- IAsyncDisposable would allow objects to have an async Dispose method.