I always wondered what is the best way to use a class Streamin C # .Net. Is it better to provide a thread that was written or provided alone? i.e:
Stream
public Stream DoStuff(...) { var retStream = new MemoryStream(); //Write to retStream return retStream; }
Unlike;
public void DoStuff(Stream myStream, ...) { //write to myStream directly }
I have always used the previous example to manage the life cycle, but I have the feeling that this is a poor way to "stream" with Streamthe lack of a better word.
I would prefer the "second method" (work with the provided stream), since it has several special advantages:
, ( 1), , Seek, ( , , - ). Seek , , .
Seek
Streams , , .
, - . .
.
- . , , , . , .
public byte[] DoStuff(...) { var retStream = new MemoryStream(); //Write to retStream return retStream.ToArray(); }