I want to create a ZipArchive file if it doesn't already exist. Then I want to open it for reading its information before I update it. So is this valid use of the discard variable _ and does it work as intended?
using (_ = ZipFile.Open(filename, ZipArchiveMode.Update)) { }
There is a similar question https://mcmap.net/q/1285781/-c-7-0-discards-and-idisposable-out-argument, he says _ doesn't call dispose when used like this:
var a = TestMethod(out _.Dispose());
out _.Dispose()
is invalid syntax.Dispose
doesn't return aref Disposable
(and I'm not sure the language could use that if it did--but I haven't tried it). See this answer for a better way to dispose a disposable output parameter. – Rawley