Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dim c as MyClass & Dim c as New MyClass

Tags:

oop

vb.net

It's a simple concept, but one I've never been taught. Can someone please explain the differences between the following 2 statements please:

Dim c as MyClass

Dim c as New MyClass
like image 906
Curtis Avatar asked Dec 18 '25 15:12

Curtis


1 Answers

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

Dim c as MyClass = New MyClass

Both are different to Dim c as MyClass: the statement without New only declares the variable, it doesn’t assign a value. This means that the variable has a default value of Nothing.

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

like image 137
Konrad Rudolph Avatar answered Dec 20 '25 11:12

Konrad Rudolph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!