Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...