What is the code snippet or shortcut for creating a constructor in Visual Studio?
Visual Studio 2010 and C#.
As mentioned by many, "ctor" and double TAB works in Visual Studio 2017, but it only creates the constructor with none of the attributes.
To auto-generate with attributes (if there are any), just click on an empty line below them and press Ctrl + .. It'll display a small pop-up from which you can select the "Generate Constructor..." option.
I have created some handy code snippets that'll create overloaded constructors as well. You're welcome to use them: https://github.com/ejbeaty/Power-Snippets
For example: 'ctor2' would create a constructor with two arguments and allow you to tab through them one by one like this:
public MyClass(ArgType argName, ArgType argName)
{
}
For Visual Studio 2017, press Ctrl + ..
If you use ReSharper, you can quickly generate constructors by typing:
If you want to see the list of all available snippets:
Press Ctrl + K and then X.
Type ctor
, and then press TAB twice.