@bommelding:
MemoryStream
is unusual in that regard, yes, and nothing really prevents you from doing so, but I also see no point at all. First, it's best practice to dispose locally constructed disposable instances using the
using
statement. Most static code analyzers will complain about not disposing the object, and you have one more thing to explain during code reviews. Second, accessing members of a disposed object should be almost always avoided. So I would prefer
using (var ms = MemoryStream()) { x = ms.ToArray(); }
any day of the week, if I really need to return the buffer. —
Groo 1 min ago