As we all aware using keyword is been used to ensure that the Dispose() method will be called on a type object implemented IDisposableinterface when it reaches declared block as shown below.

using(Stream myStream = new MemoryStream(int.MaxValue))
{

}

Here, when the block reaches by the runtime,  Dispose() method will be called on myStream object by the runtime as it is declared in using block.

In C# 8.0, this using block made more easy to avoid some nesting using blocks as follows.

using(Stream myStream = new MemoryStream(int.MaxValue))
{
     using (Stream myStream1 = new MemoryStream(int.MaxValue))
     {

     }
}

As we can see in the above statement we declared inner using block and it can go to any extent. In C# 8.0, it made simple as below.

using Stream myStream = new MemoryStream(int.MaxValue);
using Stream myStream1 = new MemoryStream(int.MaxValue);

As we can see, just need to prefix these variables by using keyword. The runtime will make sure to call the Dispose method when it comes out of the declared block.

Happy Coding 🙂