Assume I have a string class with a method ToStream()
.
class FooBar
{
pubic Stream ToStream( )
{
byte[ ] barFooBytes = Encoding.UTF8.GetBytes( this.BarFoo );
return new MemoryStream( barFooBytes );
}
}
Now assume I have a class getting this stream.
class BarFoo
{
pubic void DoCrazyStuff( )
{
using( Stream fooBarStream = ( new FooBar( ) ).ToStream( ) )
{
// Doing some really crazy stuff!
}
}
}
Does it still make sense to use a using
outside of the method creating the stream?
Hint: This is not an actual real life scenario. It's a pure technical question of interest. So this code is minified just to clarify the question.
>`, does it make sense ? The only correct answer is: **It depends**. We need to know more details in order to give an educated guess.
– Fabjan Nov 28 '18 at 09:21