Could someone explain to me the NEW keyword is used for

Mykro

Newcomer
Joined
Aug 31, 2003
Messages
23
Location
Dana Point Ca.
I'm trying to get a handle on how the NEW keyword is used in VB.NET. could someone shed some light towards this newcomer to VB.NET. Please explain in simplest terms

Thanks :D
 
When you have an object, the New keywork creates a new instance of the object and initializes it. If you don't use the New keyword, VB.NET doesn't know what sort of object it is, and it effectivity is nothing (and IS nothing).
 
It's also used to define constructors. So if you had something like this:

Code:
Public Class MyNumber
        Private mNum as Long

        Public Sub New(StartingNumber as Long)
            mNum = StartingNumber
        End Sub

End Class

You could then define use the class like this:

Code:
        Dim x As New MyNumber(4)

        Dim y As MyNumber
        y = New MyNumber(4)
 
Back
Top