When to use 'As New' to declare an object

Discussion in 'ASP .Net' started by Ritu, Aug 13, 2003.

  1. Ritu

    Ritu Guest

    I am just migrating from ASP and VB to .NET and what
    confuses me the most is what is an Object and what is not.
    Most Data Types (even the basic ones) are treated like
    objects and have functions associated with them. However,
    we do not instantiate all of them using an 'As New' as was
    the norm earlier.

    This might sound like a silly question, but could someone
    thrash out this basic concept for me please.

    Thanks in Advance
    Ritu
     
    Ritu, Aug 13, 2003
    #1
    1. Advertising

  2. Ritu

    Marina Guest

    The primitive types are value types (aka structures). This means that all
    their members get initialized to default values when the object is declared,
    thus there is no need to call new to create an instance. There other
    behaviors that are different, such as:
    Dim i as Integer = 2
    Dim j as Integer
    j=i

    j and i are pointing to different instances of the Integer structure - they
    both hold the value '2'. Something like this:
    Dim i as New SqlConnection()
    Dim j as SqlConnection
    j = i

    Now, j and i are pointing to the exact same instance of SqlConnection in
    memory. Because SqlConnection is a reference type, not a value type, New
    had to be used to initialize an instance. Otherwise the reference would be
    pointing to nothing.

    "Ritu" <> wrote in message
    news:005901c361af$43850cf0$...
    >
    > I am just migrating from ASP and VB to .NET and what
    > confuses me the most is what is an Object and what is not.
    > Most Data Types (even the basic ones) are treated like
    > objects and have functions associated with them. However,
    > we do not instantiate all of them using an 'As New' as was
    > the norm earlier.
    >
    > This might sound like a silly question, but could someone
    > thrash out this basic concept for me please.
    >
    > Thanks in Advance
    > Ritu
     
    Marina, Aug 13, 2003
    #2
    1. Advertising

  3. It still works mostly the same as always.
    The main difference, as you've discovered, is that everything basically acts
    as an object now. This is very handy.
    But underneath it all you still have value types and reference types.
    Integers and Bytes and things are still value types so you don't need to
    explicitly instantiate them.
    Most other object types need to be instantiated, unless the object's methods
    are declared as shared (static in C#).

    --
    I hope this helps,
    Steve C. Orr, MCSD
    http://Steve.Orr.net
    Developer for Hire


    "Ritu" <> wrote in message
    news:005901c361af$43850cf0$...
    >
    > I am just migrating from ASP and VB to .NET and what
    > confuses me the most is what is an Object and what is not.
    > Most Data Types (even the basic ones) are treated like
    > objects and have functions associated with them. However,
    > we do not instantiate all of them using an 'As New' as was
    > the norm earlier.
    >
    > This might sound like a silly question, but could someone
    > thrash out this basic concept for me please.
    >
    > Thanks in Advance
    > Ritu
     
    Steve C. Orr, MCSD, Aug 13, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    16
    Views:
    504
    Mike Smith
    Jul 11, 2005
  2. Sam Waller
    Replies:
    2
    Views:
    480
    Stuart Golodetz
    Jul 14, 2006
  3. Weng Tianxiang

    How to declare a port with a new type

    Weng Tianxiang, Jul 7, 2010, in forum: VHDL
    Replies:
    8
    Views:
    693
    Martin Thompson
    Jul 16, 2010
  4. Noah Roberts

    Create and declare new type...

    Noah Roberts, Mar 22, 2011, in forum: C++
    Replies:
    1
    Views:
    257
    Victor Bazarov
    Mar 22, 2011
  5. Replies:
    2
    Views:
    502
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page