Make initializer inside using scope #7751
Unanswered
ahdung
asked this question in
Language Ideas
Replies: 2 comments 17 replies
-
This belongs at https://github.com/dotnet/roslyn-analyzers/, however the analyzer is technically correct.
If |
Beta Was this translation helpful? Give feedback.
12 replies
-
How about: var folderBrowserDialog = using new FolderBrowserDialog
{
ShowNewFolderButton = true,
Description = Title,
SelectedPath = InitialDirectory,
}; Here, using var temp = new FolderBrowserDialog();
temp.ShowNewFolderButton = true;
temp.Description = Title;
temp.SelectedPath = InitialDirectory;
var fbd = temp; |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Above codes actually is:
So when
folderBrowserDialog.ShowNewFolderButton = true;
occurred exception,folderBrowserDialog
will not be disposed. So for avoid this issue we have to abandon using object initializer:which is no longer elegant, so please make initializer statement using-friendly.
Ref: https://dev.to/powerz/dangerous-using-declaration-c-80-3h86
Beta Was this translation helpful? Give feedback.
All reactions