As Drew has already covered the bases from a technical standpoint, I'll just chip in 
with my non-technical reason for also choosing
to do initialization in the ctor (#2 choice if you read Drew's post):

I like to have one place to start from to see what's going on when I look through a 
class. It's very easy to see what gets
initialized and in what order, without missing anything, when you do the 
initialization in the ctor.

I also like to group my instance variables with their corresponding property 
declaration (if there is one), so I don't have a
section where all the instance vars are grouped (although my property declarations 
are). This makes it even more desirable to use
the ctor(s) for initializing everything.

Keep Smilin'
Ed Stegman

-----Original Message-----
From:Rolls, Robert

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

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