The C# 8 using statement translates to try-finally blocks (1).
Your example
int bytesRead;
byte() fileBytes = new byte(4096);
using FileStream fileStream = new FileStream(...);
while ((bytesRead = fileStream.Read(fileBytes, 0, fileBytes.Length)) > 0)
{
... // Do something
}
Will be translated to something like:
int bytesRead;
byte() fileBytes = new byte(4096);
FileStream fileStream = new FileStream(...);
try
{
while ((bytesRead = fileStream.Read(fileBytes, 0, fileBytes.Length)) > 0)
{
... // Do something
}
}
finally()
{
fileStream.Dispose();
}
Your concern that you can’t see the scope is invalid. The object will always be disposed.
Coding style preferences are just that, preferences. Some people like option 1 and others like option 2. When nesting multiple usings, option 2 becomes a bit messy because of indentations.