J
Jure Bogataj
Hello!
I'm using .NET 2005 (C#) and I've come across using statement. It seems ok,
I was just wondering one thing. What if I returned object inside using
statement using RETURN directive. Is returned object valid or not?
For example:
public FileStream Func1()
{
...
using (FileStream fs = new FileStream(<some params>))
{
// Do sth with FS
return fs;
}
}
is on return from Func1 FileStream object returned valid, since it is called
from inside using statement? Does "using" statement *always* call Dispose,
or does it just decrement object's reference? If its the first (called
Dispose), than I must not use using statement for that kind of operations or
on variables I must return?
Thanks in advance!
Best regards,
Jure
I'm using .NET 2005 (C#) and I've come across using statement. It seems ok,
I was just wondering one thing. What if I returned object inside using
statement using RETURN directive. Is returned object valid or not?
For example:
public FileStream Func1()
{
...
using (FileStream fs = new FileStream(<some params>))
{
// Do sth with FS
return fs;
}
}
is on return from Func1 FileStream object returned valid, since it is called
from inside using statement? Does "using" statement *always* call Dispose,
or does it just decrement object's reference? If its the first (called
Dispose), than I must not use using statement for that kind of operations or
on variables I must return?
Thanks in advance!
Best regards,
Jure