Default Constructor in VS 2005?

D

David Veeneman

I'm digging into VS 2005, and one of the first things I noticed is that VS
doesn't create a default constructor when it creates a new class. Is there a
user option to have VS create a default constructor in all new classes, or
do I have to create my own template? Thanks in advance.
 
R

Richard Blewett [DevelopMentor]

You are right it doesn't but then the com[iler will create one for you if you don't supply one yourself. So unless you really need an explicit constructor (you can use field initializers instead for most things) then leave the template alone (Microsoft got feedback that most people delete that constractor form the template).

If you want a constructor you know you can just type "ctor" (without the quotes) and press TAB once (or twice depending on which build you have) and it will generate the code you need.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I'm digging into VS 2005, and one of the first things I noticed is that VS
doesn't create a default constructor when it creates a new class. Is there a
user option to have VS create a default constructor in all new classes, or
do I have to create my own template? Thanks in advance.
 
J

Jon Shemitz

Richard Blewett said:
If you want a constructor you know you can just type "ctor" (without the quotes) and press TAB once (or twice depending on which build you have) and it will generate the code you need.

Hmm, I didn't know that. It's ... almost cool. Only "almost", because
it reeks of the really limited interface stub support in VS.2003. I'd
have expected an "Office autocorrect" style menu, like you get for
interface implementation stubs, or undeclared methods: Ie, mousing
over a class name with no contructor gives you a hollow box you can
click on to get a popup menu that offers to generate a constructor.
 
D

David Veeneman

No, I didn't know about the 'ctor' trick. That, and the other code snippets
shortcuts, are pretty cool. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top