Results 1 to 3 of 3

Thread: Question on use of NEW Keyword

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    13

    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

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    13

    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
  •  



Click Here to Expand Forum to Full Width