Visual Studio often recommends the ‘simple using’ statement rather than brackets. However, which is actually better?
I quite like the simple using statement, but I can see it potentially causing problems since you can’t see the scope. The simple using seems a bit less clear that it’s a using statement.
1. Simple using
int bytesRead;
byte() fileBytes = new byte(4096);
using FileStream fileStream = new FileStream(...);
while ((bytesRead = fileStream.Read(fileBytes, 0, fileBytes.Length)) > 0)
{
... // Do something
}
2. Bracketed using
int bytesRead;
byte() fileBytes = new byte(4096);
using FileStream fileStream = new FileStream(...)
{
while ((bytesRead = plaintext.Read(fileBytes, 0, fileBytes.Length)) > 0)
{
... // Do something
}
}