C
cgough
My true programming language is C++. I am at best a VB6 hacker that is
just getting into VB.NET. I have a quick question about when to new and
when not to new.
Consider the following 2 classes. In the first I new an integer and
assign it to i, in the second one I don't bother. In both cases, an
integer is created and I can use it.
If I try to use a Collection object without New, I get a NULL reference
exception.
What I am looking for is some rules on when to New and when not to New.
Seems confusing ( from a C++ perspective) that in some cases
declaration instantiates an object and sometimes it doesn't.
Public Class Initialization
Public Sub New()
i = New Integer()
End Sub
Public Property Myint() As Integer
Get
Return i
End Get
Set(ByVal Value As Integer)
i = Value
End Set
End Property
Private i As Integer
End Class
Public Class Initialization
Public Sub New()
End Sub
Public Property Myint() As Integer
Get
Return i
End Get
Set(ByVal Value As Integer)
i = Value
End Set
End Property
Private i As Integer
End Class
Thanks,
Chris
just getting into VB.NET. I have a quick question about when to new and
when not to new.
Consider the following 2 classes. In the first I new an integer and
assign it to i, in the second one I don't bother. In both cases, an
integer is created and I can use it.
If I try to use a Collection object without New, I get a NULL reference
exception.
What I am looking for is some rules on when to New and when not to New.
Seems confusing ( from a C++ perspective) that in some cases
declaration instantiates an object and sometimes it doesn't.
Public Class Initialization
Public Sub New()
i = New Integer()
End Sub
Public Property Myint() As Integer
Get
Return i
End Get
Set(ByVal Value As Integer)
i = Value
End Set
End Property
Private i As Integer
End Class
Public Class Initialization
Public Sub New()
End Sub
Public Property Myint() As Integer
Get
Return i
End Get
Set(ByVal Value As Integer)
i = Value
End Set
End Property
Private i As Integer
End Class
Thanks,
Chris