C# 8 : Nullable Reference Types, Null Forgiving and Null Coalescing Assignment

There are some properties that ought to be learned together to understand the complete picture. In this blog post, we will address two of such features. Nullable Reference Types Let us begin by writing some code. public class Foo { public Bar Bar { get; set; } } public class Bar { public int Id … Continue reading C# 8 : Nullable Reference Types, Null Forgiving and Null Coalescing Assignment

C# 8 : Asynchronous Streams and Static Local Functions

Asynchronous StreamHow often have you come across situations when you would want to return streams of data from an asynchronous method ? Plenty of times I would guess. The asynchronous methods were pretty limited when return data in streams, but not any longer.  Consider the following code. // Will not compile public static async Task<IEnumerable<int>> Generate(int max) { for (int i = 0; i < max; i++) { await Task.Delay(1000); yield return i; } } The above code would not compile. There is no way you could `yield return` values (or in other words, stream values) from an asynchronous method. This would have been a highly useful situation when you want to iterate over results from a query over an extremely large database. There are other countless situation the ability to stream data from asynchronous method could be useful. However, prior to C# 8.0, we were severely handicapped in such a situation. With C# 8.0, .Net comprises a new Type called the IAsyncEnumerable, which allows us to accomplis this. The above code could be now rewritten … Continue reading C# 8 : Asynchronous Streams and Static Local Functions

C# 8 : Using Declaration

The next feature we would explore in C# 8 is more off a syntatic sugar, but neverthless it is important to understand the difference between the new syntax and the original feature it is covering up. We are all aware of the Using statements, which allows correct usage of the IDisposible objects. Using Statement Let … Continue reading C# 8 : Using Declaration

C# 8 : Index and Range

While C# as a language has grown leaps and bounds, one are that was least addressed was manipulation of collections (arrays in particular). C# 8 looks to change exactly that by introducing two new Types. System.Index System.Index is a structure that can be used to Index a collection either from the start or the end. … Continue reading C# 8 : Index and Range

C# 8.0 : Default Implementation of Interface Members

The way C# language is evolving is definitely exciting and one feature that truly makes the wait for C# 8.0 all the more exciting is default implementation of interfaces. Since the onset, interfaces were behaviors characterized by member signatures, strictly disallowing any implementation. All that is going to change when C# 8.0 rolls out, as … Continue reading C# 8.0 : Default Implementation of Interface Members