Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
71 views
in Technique[技术] by (71.8m points)

c# - My app is not going into static void processFile and its going into catch and closing why is that?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...