views:

120

answers:

4

Using C# in VS2005, is there special way to create properties in the IDE or can you just type out the getters and setters?

+2  A: 

Well, you can type the word prop and then hit tab twice for a code snippet. propg will generate a readonly property (only a getter).

Dan Tao
+1 for knowing that it works in VS2005, just with the old-fashioned style backing field...
Pretzel
+3  A: 

In the code editor type prop + Tab + Tab

Darin Dimitrov
+1 for indirectly educating me on the <kbd> tag. :)
Pretzel
Correct me if I'm wrong, but doesn't this create an automatic property which only has been added in C# 3.0 / Visual Studio *2008*? So I think this won't work for the OP then :( In case it shouldn't work it is possible to define one's own custom snippets as described here: http://aspalliance.com/863
0xA3
@0xA3: No, it does work for VS2005 -- it creates a property the "old-fashioned" way (with a backing field plus a getter/setter).
Dan Tao
@Dan Tao: Thanks, didn't know that.
0xA3
+1  A: 

I think what you're after are code snippets, have a look here and here.

There are also snippets besides prop for properties that you may save you time, see here for the list of built-in snippets.

Nick Craver
+1  A: 

There are built-in code snippets - try typing prop then pressing TAB twice. This will automatically generate the code for a property with a getter a setter, and let you tab between a couple of points to declare property name and type.

Graham Clark