Connecting Tech Pros Worldwide Forums | Help | Site Map

When to use "new" syntax in object creation

Jean Stax
Guest
 
Posts: n/a
#1: Nov 15 '05
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.

Lloyd Dupont
Guest
 
Posts: n/a
#2: Nov 15 '05

re: When to use "new" syntax in object creation


> As far as I understand, when I create value type without "new" syntax[color=blue]
> 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?[/color]

probably so, yes...
anyway you can't define parameterless constructor on struct ...
[color=blue]
> 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?[/color]
the other case are when someone else call "new" for you ...


Closed Thread