using StreamWriter sw = new StreamWriter(stream);
// Your other code here
Is the offending line. On earlier versions of C# this must be
using (StreamWriter sw = new StreamWriter(stream))
{
// Your other code here
}
Using declarations (the first version) were introduced to avoid the constant ramping to the right that happens with using statements/blocks (the second version). They are functionally identical (as long as the using block goes to the end of the containing scope), although a trivia difference is that using declarations must declare a local variable (the other form is not required to introduce a local).
If you have an up-to-date compiler it may also just be that your project file or target platform is forcing an earlier C# version. You can explicitly target higher C# versions by editing the csproj.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…