Skip to main content

Posts

C# 8.0 feature - Asynchronous streams

This blog post is part of series of latest C# 8.0 features . In this post we will explore in detail about the new feature Nullable reference types. In C# data structure IEnumerable plays an important role, language supports special syntax to create and use them. We have used foreach statement to iterate through the array in previous program, which was synchronous. async and await were added to C# with version 5.0 to deal with asynchronous tasks to avoid blocking the thread. A program can asynchronously await and do other stuff until result it available or required to proceed.  Asynchronous streams combines both IEnumerables and C# together. Let's take a look at how it can be used with the help of below code snippet.                  using System.Collections.Generic;     using System.Net.Http;     using System.Threading.Tasks;     using static System.Console;     na...
Recent posts

C# 8.0 feature - Ranges and indices

This blog post is part of series of latest C# 8.0 features . In this post we will explore in detail about the new feature Nullable reference types. With latest C# 8.0 feature you can use simple expression to slice part of array. Add below code snippet to check this feature.          static void Main( string [] args)         {             string [] characters = {                 "Daenerys Targaryen" , "Eddard Stark" , "Catelyn Stark" , "Jon Snow" , "Sansa Stark" , "Arya Stark" , "Robb Stark" , "Jaime Lannister" , "Cersei Lannister"             };             WriteLine( "Stark Family:" );            ...

C# 8.0 feature - Nullable reference types

This blog post is part of series of latest C# 8.0 features . In this post we will explore in detail about the new feature Nullable reference types. Well you read it right! Till now reference types were by default nullable i.e. they can hold null value. But that increases the chances for null reference exceptions. Not every time developers handled it correctly or it could be some other assembly or API not behaving correctly which causing your code to throw an exception. With C# 8.0 nullable reference types compiler will warn you about unsafe behavior of code and possible occurrences of any possible dereferences of null reference. You can only assign null to variable if it is nullable. Lets look at the below code snippet. Compiler is not showing any warnings or errors. But if you try to run the application it will throw null reference exception. In this scenario it is straightforward but in real life you might be receiving data from other assembly or API that could return you bad d...