views:

119

answers:

4

I have seen some people creating properties in C# really fast but I don't know how they did it.

Does anyone know what short cut are available in Visual Studio (currently using 2010) to create properties?

I am using C#.

ex.

public string myString {get;set;}

Thanks.

+9  A: 

You could type "prop" and then press tab, that will generate the following.

public TYPE Type { get; set; }

Then you change "TYPE" and "Type"

public string myString {get; set;}

You can also get the full property typing "propfull" and then tab, that would generate the field and the full property.

private int myVar;

public int MyProperty
{
    get { return myVar;}
    set { myVar = value;}
}
Cesar Lopez
Didn't know about this, thanks.
Mike
You have forgotten to name it "Code Snippet" :)
PVitt
@PVitt:Thanks I did not know the name :-)
Cesar Lopez
You can also create your own snippets with the snippet editor.
Johann Blais
+1  A: 

Resharper offers property generation in its extensive feature set. (It's not cheap though, unless you're working on an open-source project.)

Paul Ruane
+4  A: 

Additionaly to Cesar Lopez answer, you can find other snippets by typing Ctrl k Ctrl x (mapped to Edit.InsertSnippet in my Visual Studio).

Patrick
@Patric: Nice it is slower but you get the full list of short cuts +1.
Cesar Lopez
+1  A: 

See my previous answer/tip

Basically click inside of your field private int _i; and then Ctrl R + E to create the standard property accessors.

Mike