“无法将void分配给隐式类型的局部变量”错误

时间:2017-02-17 07:37:05

标签: c# zipfile

using (ZipFile zip = ZipFile.Read(fu.PostedFile.InputStream)){                    
    string extractPath = Server.MapPath("~/Uploads/");
    string oldPathImg = Server.MapPath("~/Uploads/RubbishData/");
    zip.ExtractSelectedEntries("name = *.docx", "",extractPath, ExtractExistingFileAction.OverwriteSilently);
    var x = zip.ExtractSelectedEntries("name = *.png");   
}

最后一行给出了错误“无法将void分配给隐式类型的局部变量”,我不明白为什么。

1 个答案:

答案 0 :(得分:0)

正如我的评论中所提到的,您使用的库有Ionic API Guide,它明确指出ExtractSelectedEntries的所有重载都没有返回类型,只是void

public void ExtractSelectedEntries(
    string selectionCriteria,
    ExtractExistingFileAction extractExistingFile
)

这意味着你的代码应该是这样的

using (ZipFile zip = ZipFile.Read(fu.PostedFile.InputStream)){                    
    string extractPath = Server.MapPath("~/Uploads/");
    string oldPathImg = Server.MapPath("~/Uploads/RubbishData/");
    zip.ExtractSelectedEntries("name = *.docx", "",extractPath, ExtractExistingFileAction.OverwriteSilently);
    zip.ExtractSelectedEntries("name = *.png"); // Cannot assign void to a variable, remove the assignment.
}