|
-
Dec 1st, 2011, 02:38 PM
#1
Thread Starter
New Member
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
-
Dec 1st, 2011, 02:50 PM
#2
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
-
Dec 1st, 2011, 02:53 PM
#3
Thread Starter
New Member
Re: Question on use of NEW Keyword
Hi techgnome
Thank you for the answer.
Jerry B
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|