Robert,

A general philosophy that can be applied is to aquire resources
late and release early, however it really depends on the nature
of the problem you are trying to solve. Sometimes its best to
do alot of upfront initialization to make response times a
little snapper in other points of execution.

There are specific instances where this is useful, for example
if you are building some kind of pooling mechanism and you
pre-initialize the pool to a certain size.

My advice to you is always consider your approach in the
context of the problem you are trying to solve but always
tend towards aquiring memory and other resources as you
need them and release them as soon as possible.

It is interesting to note however that when you compile
the following code:

        public class Data
        {

                public string Field1 = "Field1 value";
                public string Field2 = "Field2 value";
                public string Field3 = null;
                public string Field4;

                public Data()
                {

                        this.Field3 = "Field3 value";
                        this.Field4 = "Field4 value";

                }

        }

The IL effectively turns out to be this (in C#):

        public class Data
        {

                public string Field1;
                public string Field2;
                public string Field3;
                public string Field4;

                public Data()
                {

                        this.Field1 = "Field1 value";
                        this.Field2 = "Field2 value";
                        this.Field3 = null;
                        this.Field3 = "Field3 value";
                        this.Field4 = "Field4 value";

                }

        }

Hope this helps!

----------------------------------------
- Mitch Denny
- [EMAIL PROTECTED]
- +61 (414) 610-141
-

-----Original Message-----
From: The DOTNET list will be retired 7/1/02
[mailto:[EMAIL PROTECTED]] On Behalf Of Rolls, Robert
Sent: Tuesday, 4 June 2002 12:09
To: [EMAIL PROTECTED]
Subject: [DOTNET] Class Member Initialization.


Do people still use the constructor to define default values to members
or has the default constructor been depreciated? Are there any reasons
not to use to the following?

public byte[] arr = new byte[1024];

rather than

public byte[] arr = null;

then within the constructor
arr = new byte[1024];


Regards,
Robert Rolls




**********************************************************************"
This correspondence is for the named person's use only. It may contain
confidential or legally privileged information or both. " No
confidentiality or privilege is waived or lost by any " mistransmission.
If you receive this correspondence in error, please immediately delete
it from your system and notify the sender.  You must not disclose, copy
or rely on any part of this correspondence if you are not the intended
recipient.

Any views expressed in this message are those of the individual sender,
except where the sender expressly, and with authority, states them to be
the views of Vodafone.

This email has been checked for viruses.
************************************************************************
**********************

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to