C
C#3y ago
OmegaLol21

Difference between variable using and statement using?

Im just wondering if there is any difference to using a using statement by doing this:
using var foo = new Bar();
foo.DoStuff();
using var foo = new Bar();
foo.DoStuff();
as opposed to doing
using (var foo = new Bar())
{
foo.DoStuff();
}
using (var foo = new Bar())
{
foo.DoStuff();
}
4 Replies
Thinker
Thinker3y ago
Only difference is that using (var foo = new Bar()) creates a new scope, at the end of which foo is disposed. Using using var foo = new Bar(); will dispose foo at the end of the method.
OmegaLol21
OmegaLol21OP3y ago
so there isnt really any performance or memory difference?
ero
ero3y ago
No Also the simple using statement still disposes at the end of the current scope That might be the end of the method, or it might not
OmegaLol21
OmegaLol21OP3y ago
ok thank yall so much for clearing that up sorry if it was a simple question lol
Want results from more Discord servers?
Add your server