Dim c like MyClass & Dim c like new MyClass

This is a simple concept, but I never taught it. Can someone please explain the differences between the following two statements:

Dim c as MyClass

Dim c as New MyClass
+3
source share
1 answer

Dim c as New MyClass is a shortcut and is strictly equivalent to the following:

Dim c as MyClass = New MyClass

Both differ from Dim c as MyClass: the operator without Newdeclares only a variable, it does not assign a value. This means that the variable has a default value Nothing.

New MyClass, on the other hand, assigns a newly created instance of this class to a variable.

+9
source

All Articles