相关疑难解决方法(0)

如何知道File.Copy成功了?

静态方法File.Copy(String, String)不返回值.如果该功能成功与否,我如何以编程方式知道?如果没有抛出异常,那么File.Copy顺利.但我问的是如何将"不例外"作为条件.

像这样的东西:

if(no exception happened){

//my code goes here

}
Run Code Online (Sandbox Code Playgroud)

编辑:我使用一个简单的计数器解决了这个问题如下:

int i=0;
try{
    File.Copy();
}
catch(e1){
    i++;
}
catch(e2){
    i++;
}

if(i==0){
    //my code goes here
}
Run Code Online (Sandbox Code Playgroud)

感谢所有贡献者.我将通过你的答案选择最好的.

.net c# exception return-value file-copying

17
推荐指数
3
解决办法
3万
查看次数

标签 统计

.net ×1

c# ×1

exception ×1

file-copying ×1

return-value ×1