Code snippet or shortcut to create a constructor in Visual Studio

前端 未结 17 1601
悲哀的现实
悲哀的现实 2020-12-23 12:57

What is the code snippet or shortcut for creating a constructor in Visual Studio?

Visual Studio 2010 and C#.

相关标签:
17条回答
  • 2020-12-23 13:38

    Type ctor, and then press the Tab key.

    0 讨论(0)
  • 2020-12-23 13:41
    1. Press Alt + Enter
    2. Select "Generate Constructor"
    3. Select required members

    A parameterized constructor is generated with the selected members.

    0 讨论(0)
  • 2020-12-23 13:42

    Type "ctor" + TAB + TAB (hit the Tab key twice). This will create the default constructor for the class you are in:

    public MyClass()
    {
    
    }
    

    It seems that in some cases you will have to press TAB twice.

    0 讨论(0)
  • 2020-12-23 13:44

    For the full list of snippets (little bits of prefabricated code) press Ctrl+K and then Ctrl+X. Source from MSDN. Works in Visual Studio 2013 with a C# project.

    So how to make a constructor

    1. Press Ctrl+K and then Ctrl+X
    2. Select Visual C#
    3. Select ctor
    4. Press Tab

    Update: You can also right-click in your code where you want the snippet, and select Insert Snippet from the right-click menu

    0 讨论(0)
  • 2020-12-23 13:44

    Type the name of any code snippet and press TAB.

    To get code for properties you need to choose the correct option and press TAB twice because Visual Studio has more than one option which starts with 'prop', like 'prop', 'propa', and 'propdp'.

    0 讨论(0)
提交回复
热议问题