473,473 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

When to use 'As New' to declare an object


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
Nov 17 '05 #1
2 1259
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" <rc****@rediffmail.com> wrote in message
news:00****************************@phx.gbl...

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

Nov 17 '05 #2
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" <rc****@rediffmail.com> wrote in message
news:00****************************@phx.gbl...

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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean...
2
by: david | last post by:
Well, as a matter of fact I_HAD_MISSED a basic thing or two, anyway, although Ollie's answer makes perfectly sense when dealing with classes, it doesn't seem to me to apply as well if you have to...
1
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
11
by: Marco Wedekind | last post by:
Hello all, I have a strange compiler behaviour with this code: ---- Begin of code snippet ---- class Base { public: static unsigned int ClassId();
8
by: Kenneth Baltrinic | last post by:
When one overrides the Equals() method of an object, one is supposed to override GetHashCode() as well and this makes good sense. But I have seen lots of people who do this and do not override the...
7
by: pedagani | last post by:
Dear comp.lang.c++, I'm trying to read a file with very long filename using ifstream. Although, the file exists the file open for read fails. Is there a restriction on the size? I'm using winXP...
2
by: nospam | last post by:
I have code that is working in one place but not another. In one spot, you click a button to open an XML file and have it read into a dataset. I then set the datasource of my datagrid to the...
5
by: WittyGuy | last post by:
Hi all, All I want to achieve is restricting the object instantiation in stack and allowing the application to instantiate the object only in heap using new operator. How to achieve this? I...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
15
by: Jess | last post by:
Hello, Sometimes declarations are all what we need when we define/declare classes (or functions?), but sometimes we need definitions. I learned that if we define a class (B) that has an object...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.