473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

When to use “new” syntax in object creation

Hi !

A couple of pretty basic questions:

Value types:

As far as I understand, when I create value type without "new" syntax
the object is considered as unutilized. Consequently, I have to
initialize its member variables manually; otherwise I would get an
exception while accessing them.
Does this means that the constructor of the object, which is created
without_new_way wouldn't be called?

Reference types:

Do I always create reference types with "new" syntax or there are some
cases when I create my object without "new" and it still will be
allocated in managed heap?

Thanks.

Jean.
Nov 15 '05 #1
1 1740
Jean Stax <je*******@hotmail.com> wrote:
A couple of pretty basic questions:

Value types:

As far as I understand, when I create value type without "new" syntax
the object is considered as unutilized. Consequently, I have to
initialize its member variables manually; otherwise I would get an
exception while accessing them.
Does this means that the constructor of the object, which is created
without_new_way wouldn't be called?
Bear in mind that you can't define a parameterless constructor for a
value type, but you can always do new ValueType() as if there *was*
one. Other than how you initialize the member variables (and when the
value is considered to be initialized) I don't think there's any
difference between the two. I'd personally try to use a constructor
wherever possible.
Reference types:

Do I always create reference types with "new" syntax or there are some
cases when I create my object without "new" and it still will be
allocated in managed heap?


You can't create an object without a "new" being involved somewhere
(with a few possible exceptions like serialization - not sure) although
you may not call the "new" yourself (eg factory methods). *All*
reference type objects are allocated on the managed heap though.

Note that when you just *declare* a reference type variable, that
doesn't create an object at all - the variable's value is undefined if
it's local, and null if it's class/instance.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2

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

Similar topics

3
by: Jim Higson | last post by:
Does anyone know a technique in javascript to transform from (for example) &hearts; to the char '♥'? I'm doing this because I have to interpret some data I got over XHTMLHTTP that isn't XML,...
3
by: John Nagle | last post by:
I have XML replies in a DOM which contain entity escapes, like "&amp;". What's the proper way to replace them with the ordinary characters? Preferably something that will work in most browsers? I...
3
by: yuanyun.ken | last post by:
hi,dear all js gurus. In my app, server responses some text like: '&nbsp;&nbsp; ' and I need display these content in textarea. But Html would convert specail characters to space, and ignore line...
5
Chrisjc
by: Chrisjc | last post by:
Good afternoon, I am seeking some php configuration help. Here is the run down I am running Windows server 2003 and IIS V6.0 I have never had issues before until now. I have Symantec Antivirus 11.0...
17
by: malathib | last post by:
Hi, I have used a rich text editor in my application. I got it from one of the site.all are JS files. My problem is, i want to call a javascript function from the iframe. Can anybody help...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.