I'm using.NET Core 3.1 project. I have two methods which accept FileStream as a parameter. Let's say something like this.
void A(FileStream fs)
{
try
{
//DO SOME OPERATIONS
}
catch (Exception ex)
{
//CODE FOR CATCH BLOCK
}
finally
{fs.close()}
}
Now there is another method let's say method B which has same structure like method A but does some different operations.
void B(FileStream fs)
{
//SAME STRUCTURE AS OF
METHOD 'A' BUT
DIFFERENTT OPERATION.
}
Now when I try to call these method one after the another with only one FileStream created, the first method that gets called closes the stream and second one can't access it.
FileStream fs=
File.open("path\for\file")
ObjectName.A(fs);
ObjectName.B(fs);
I can't do the steps mentioned above with this design of methods. But also, closing the stream is necessary. How can I make the stream get opened explicitly in methods? Or is there any other way of designing those methods so that I can achieve calling them one after another with same FileStream?