Question on use of NEW Keyword
Hi
First off let me say that I am essentially new to VB.NET, i.e; still learning. Also, I hope that this is the right place to post this question.
In a Project I have a Class module defined as:
Public Class Def
Public Id As String
Public Meaning As String
.
.
Public Code As Integer
End Class
Now in another Class module, Class A, Class B, etc., to create an instance of Def I use:
Private LocalDef as New Def
Is that statement identical to:
Private LocalDef as Def = new Def
If not, what is the difference?
Thanks in advance for your help.
Jerry B
Re: Question on use of NEW Keyword
they are exactly the same... the difference is that one requires more keystrokes than the other. The first will work for any object that has a public constructor. Not all objects do... for instance, a DataRow in a datatable... you can't simply do this:
Code:
Dim myNewDataRow as New DataRow
DataRow doesn't have a public constructor...you have to call it using the AddRow of the datatable:
Code:
Dim myNewDataRow as DataRow = myDataTable.AddRow()
-tg
Re: Question on use of NEW Keyword
Hi techgnome
Thank you for the answer.
Jerry B