Are there any overheads to using the following sytax:
Form1 myForm = new Form1();
myForm.Show();
As opposed to:
Form1 myForm;
myForm = new Form1();
myForm.Show();
When I was learning VB6, I was told doing the quivelent in VB had an overhead - is the same true in .NET?
There is no difference in .Net.
But in VB6 As New
was evil. It had a special meaning: it created an auto-instantiating variable. You could never get a null reference exception with these variables. The VB6 runtime would automatically create a new instance of the object for you.
Dim x As New Foo
x.Bar = 10 ' creates a new Foo '
Set x = Nothing ' destroys the first Foo'
x.Bar = 20 ' NO ERROR - creates a second Foo '
This behaviour was considered evil by most right-thinking programmers: and we avoided As New
like the plague.
But in VB.Net (and C#) there is no difference between Dim x As New Foo
and Dim x As Foo: Set x = New Foo
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