Is there any way to refactor this code to not have to use a temporary variable and still use the syntactic sugar associated with object initializers?
FrmSomeForm someTempForm = new FrmSomeForm()
{
SomePropA = "A",
SomePropB = "B",
SomePropC = "C"
};
using (FrmSomeForm someForm = someTempForm)
{
someForm.ShowDialog();
}
using (FrmSomeForm someForm = new FrmSomeForm())
{
someForm.SomePropA = "A";
someForm.SomePropB = "B";
someForm.SomePropC = "C";
someForm.ShowDialog();
}
I think that is the simplest way and even the more readable in my opinion ...
Keep things simple :-)
using (FrmSomeForm someForm = new FrmSomeForm(){
SomePropA = "A",
SomePropB = "B",
SomePropC = "C"
})
{
someForm.ShowDialog();
}
doesn't this work? oO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With