2010-11-24 37 views

回答

10

他们将在文本顺序执行,并且被布置在相反的顺序 - 所以localFileSream将首先被设置,然后ftpStream

基本上你的代码就相当于:

using (Stream ftpStream = ...) 
{ 
    using (FileStream localFileStream = ...) 
    { 
     // localFileStream will be disposed when leaving this block 
    } 
    // ftpStream will be disposed when leaving this block 
} 

它比这进一步虽然。你的代码是当量(撇开不同类型的localFileStream)本:

using (Stream ftpStream = ..., localFileStream = ...) 
{ 
    ... 
} 
2

是。此语法只是嵌套using语句的快捷方式或替代方法。您所做的只是省略第一个using声明中的括号。它相当于:

using (Stream ftpStream = ftpResponse.GetResponseStream()) 
{ 
    using (FileStream localFileStream = (new FileInfo(localFilePath)).Create()) 
    { 
     //insert your code here 
    } 
} 
相关问题