Code-snippet or short cut to create a constructor in Visual Studio











up vote
130
down vote

favorite
13












What is the code-snippet or shortcut to create a constructor in Visual Studio?



Visual Studio 2010 and C#.



I've used it before, but I can't remember.










share|improve this question




























    up vote
    130
    down vote

    favorite
    13












    What is the code-snippet or shortcut to create a constructor in Visual Studio?



    Visual Studio 2010 and C#.



    I've used it before, but I can't remember.










    share|improve this question


























      up vote
      130
      down vote

      favorite
      13









      up vote
      130
      down vote

      favorite
      13






      13





      What is the code-snippet or shortcut to create a constructor in Visual Studio?



      Visual Studio 2010 and C#.



      I've used it before, but I can't remember.










      share|improve this question















      What is the code-snippet or shortcut to create a constructor in Visual Studio?



      Visual Studio 2010 and C#.



      I've used it before, but I can't remember.







      c# visual-studio constructor code-snippets shortcut






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 26 at 17:31









      Peter Mortensen

      13.3k1983111




      13.3k1983111










      asked Oct 6 '10 at 14:42







      user467058































          13 Answers
          13






          active

          oldest

          votes

















          up vote
          263
          down vote



          accepted










          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.






          share|improve this answer



















          • 7




            Minor correction, I think you need to hit Tab twice.
            – Hans Olsson
            Oct 6 '10 at 14:47










          • @ho1: it works if you press tab once.
            – Amra
            Oct 6 '10 at 14:49










          • Not for me (typing ctor only shows the intellisense box, then I have to type Tab once to close that and once to "use" the snippet), but might be some setting somewhere...
            – Hans Olsson
            Oct 6 '10 at 16:02






          • 1




            In addition to this technique. If you make use of the class with a specific signature, you can refactor to get visual studio to generate the constructor for you. Also if this is a default constructor and you are not doing anything with it, then it is assumed to be there by default.
            – James
            Jul 15 '12 at 10:49






          • 1




            Once or twice is a setting thing. I had this issue with a 1-letter-snippet and changed some (IntelliSense) settings to make 1 Tab work. ctor works for me with 1 hit though.
            – Bitterblue
            Mar 3 '14 at 7:54




















          up vote
          19
          down vote













          If you want to see the list of all available snippets:



          Press Ctrl + K and then X.






          share|improve this answer






























            up vote
            6
            down vote













            Type ctor, and then press TAB twice.






            share|improve this answer






























              up vote
              5
              down vote













              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






              share|improve this answer






























                up vote
                4
                down vote













                In Visual Studio 2010, if you type "ctor" (without the quotes), IntelliSense should load, showing you "ctor" in the list. Now press TAB twice, and you should have generated an empty constructor.






                share|improve this answer






























                  up vote
                  3
                  down vote













                  Simply type ctor then press TAB.






                  share|improve this answer






























                    up vote
                    3
                    down vote













                    Type ctor, and then press the Tab key.






                    share|improve this answer






























                      up vote
                      3
                      down vote













                      Type ctor and Tab.



                      ََََََََََ






                      share|improve this answer






























                        up vote
                        2
                        down vote













                        I don't know about Visual Studio 2010, but in Visual Studio 2008 the code snippet is 'ctor'.






                        share|improve this answer























                        • It is the same for vs-2008 and vs-2008, and I think is also the same for vs-2005 but not 100% sure.
                          – Amra
                          Oct 6 '10 at 14:48


















                        up vote
                        2
                        down vote













                        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'.






                        share|improve this answer






























                          up vote
                          1
                          down vote













                          For Visual Studio 2017 press "Ctrl + ."






                          share|improve this answer

















                          • 1




                            It doesn't work for generating a constructor.
                            – azish
                            Aug 24 at 12:04






                          • 1




                            I tried and it's working.. Please read this link docs.microsoft.com/en-us/visualstudio/ide/reference/…
                            – sadrag
                            Aug 24 at 12:25


















                          up vote
                          1
                          down vote













                          Should you be interested in creating the 'ctor' or a similar class-name-injecting snippet from scratch, create a .snippet file in the C# snippets directory (for example C:VS2017VC#Snippets1033Visual C#C#Snippets.snippet) with this XML content:



                          <CodeSnippets>
                          <CodeSnippet>
                          <Header>
                          <Title>ctor</Title>
                          <Shortcut>ctor</Shortcut>
                          </Header>
                          <Snippet>
                          <Declarations>
                          <Literal Editable="false"><ID>classname</ID><Function>ClassName()</Function></Literal>
                          </Declarations>
                          <Code>
                          <![CDATA[public $classname$($end$)
                          {

                          }]]>
                          </Code>
                          </Snippet>
                          </CodeSnippet>
                          </CodeSnippets>


                          This snippet injects the current class name by way of calling C# code snippet function ClassName(), detailed on this docs.microsoft page.



                          The end result of expanding this code snippet:



                          'ctor' snippet



                          Constructor end result






                          share|improve this answer






























                            up vote
                            0
                            down vote













                            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.






                            share|improve this answer





















                              Your Answer






                              StackExchange.ifUsing("editor", function () {
                              StackExchange.using("externalEditor", function () {
                              StackExchange.using("snippets", function () {
                              StackExchange.snippets.init();
                              });
                              });
                              }, "code-snippets");

                              StackExchange.ready(function() {
                              var channelOptions = {
                              tags: "".split(" "),
                              id: "1"
                              };
                              initTagRenderer("".split(" "), "".split(" "), channelOptions);

                              StackExchange.using("externalEditor", function() {
                              // Have to fire editor after snippets, if snippets enabled
                              if (StackExchange.settings.snippets.snippetsEnabled) {
                              StackExchange.using("snippets", function() {
                              createEditor();
                              });
                              }
                              else {
                              createEditor();
                              }
                              });

                              function createEditor() {
                              StackExchange.prepareEditor({
                              heartbeatType: 'answer',
                              convertImagesToLinks: true,
                              noModals: true,
                              showLowRepImageUploadWarning: true,
                              reputationToPostImages: 10,
                              bindNavPrevention: true,
                              postfix: "",
                              imageUploader: {
                              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                              allowUrls: true
                              },
                              onDemand: true,
                              discardSelector: ".discard-answer"
                              ,immediatelyShowMarkdownHelp:true
                              });


                              }
                              });














                               

                              draft saved


                              draft discarded


















                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3873702%2fcode-snippet-or-short-cut-to-create-a-constructor-in-visual-studio%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown
























                              13 Answers
                              13






                              active

                              oldest

                              votes








                              13 Answers
                              13






                              active

                              oldest

                              votes









                              active

                              oldest

                              votes






                              active

                              oldest

                              votes








                              up vote
                              263
                              down vote



                              accepted










                              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.






                              share|improve this answer



















                              • 7




                                Minor correction, I think you need to hit Tab twice.
                                – Hans Olsson
                                Oct 6 '10 at 14:47










                              • @ho1: it works if you press tab once.
                                – Amra
                                Oct 6 '10 at 14:49










                              • Not for me (typing ctor only shows the intellisense box, then I have to type Tab once to close that and once to "use" the snippet), but might be some setting somewhere...
                                – Hans Olsson
                                Oct 6 '10 at 16:02






                              • 1




                                In addition to this technique. If you make use of the class with a specific signature, you can refactor to get visual studio to generate the constructor for you. Also if this is a default constructor and you are not doing anything with it, then it is assumed to be there by default.
                                – James
                                Jul 15 '12 at 10:49






                              • 1




                                Once or twice is a setting thing. I had this issue with a 1-letter-snippet and changed some (IntelliSense) settings to make 1 Tab work. ctor works for me with 1 hit though.
                                – Bitterblue
                                Mar 3 '14 at 7:54

















                              up vote
                              263
                              down vote



                              accepted










                              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.






                              share|improve this answer



















                              • 7




                                Minor correction, I think you need to hit Tab twice.
                                – Hans Olsson
                                Oct 6 '10 at 14:47










                              • @ho1: it works if you press tab once.
                                – Amra
                                Oct 6 '10 at 14:49










                              • Not for me (typing ctor only shows the intellisense box, then I have to type Tab once to close that and once to "use" the snippet), but might be some setting somewhere...
                                – Hans Olsson
                                Oct 6 '10 at 16:02






                              • 1




                                In addition to this technique. If you make use of the class with a specific signature, you can refactor to get visual studio to generate the constructor for you. Also if this is a default constructor and you are not doing anything with it, then it is assumed to be there by default.
                                – James
                                Jul 15 '12 at 10:49






                              • 1




                                Once or twice is a setting thing. I had this issue with a 1-letter-snippet and changed some (IntelliSense) settings to make 1 Tab work. ctor works for me with 1 hit though.
                                – Bitterblue
                                Mar 3 '14 at 7:54















                              up vote
                              263
                              down vote



                              accepted







                              up vote
                              263
                              down vote



                              accepted






                              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.






                              share|improve this answer














                              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.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Sep 26 at 18:47









                              Peter Mortensen

                              13.3k1983111




                              13.3k1983111










                              answered Oct 6 '10 at 14:45









                              Amra

                              13.3k237288




                              13.3k237288








                              • 7




                                Minor correction, I think you need to hit Tab twice.
                                – Hans Olsson
                                Oct 6 '10 at 14:47










                              • @ho1: it works if you press tab once.
                                – Amra
                                Oct 6 '10 at 14:49










                              • Not for me (typing ctor only shows the intellisense box, then I have to type Tab once to close that and once to "use" the snippet), but might be some setting somewhere...
                                – Hans Olsson
                                Oct 6 '10 at 16:02






                              • 1




                                In addition to this technique. If you make use of the class with a specific signature, you can refactor to get visual studio to generate the constructor for you. Also if this is a default constructor and you are not doing anything with it, then it is assumed to be there by default.
                                – James
                                Jul 15 '12 at 10:49






                              • 1




                                Once or twice is a setting thing. I had this issue with a 1-letter-snippet and changed some (IntelliSense) settings to make 1 Tab work. ctor works for me with 1 hit though.
                                – Bitterblue
                                Mar 3 '14 at 7:54
















                              • 7




                                Minor correction, I think you need to hit Tab twice.
                                – Hans Olsson
                                Oct 6 '10 at 14:47










                              • @ho1: it works if you press tab once.
                                – Amra
                                Oct 6 '10 at 14:49










                              • Not for me (typing ctor only shows the intellisense box, then I have to type Tab once to close that and once to "use" the snippet), but might be some setting somewhere...
                                – Hans Olsson
                                Oct 6 '10 at 16:02






                              • 1




                                In addition to this technique. If you make use of the class with a specific signature, you can refactor to get visual studio to generate the constructor for you. Also if this is a default constructor and you are not doing anything with it, then it is assumed to be there by default.
                                – James
                                Jul 15 '12 at 10:49






                              • 1




                                Once or twice is a setting thing. I had this issue with a 1-letter-snippet and changed some (IntelliSense) settings to make 1 Tab work. ctor works for me with 1 hit though.
                                – Bitterblue
                                Mar 3 '14 at 7:54










                              7




                              7




                              Minor correction, I think you need to hit Tab twice.
                              – Hans Olsson
                              Oct 6 '10 at 14:47




                              Minor correction, I think you need to hit Tab twice.
                              – Hans Olsson
                              Oct 6 '10 at 14:47












                              @ho1: it works if you press tab once.
                              – Amra
                              Oct 6 '10 at 14:49




                              @ho1: it works if you press tab once.
                              – Amra
                              Oct 6 '10 at 14:49












                              Not for me (typing ctor only shows the intellisense box, then I have to type Tab once to close that and once to "use" the snippet), but might be some setting somewhere...
                              – Hans Olsson
                              Oct 6 '10 at 16:02




                              Not for me (typing ctor only shows the intellisense box, then I have to type Tab once to close that and once to "use" the snippet), but might be some setting somewhere...
                              – Hans Olsson
                              Oct 6 '10 at 16:02




                              1




                              1




                              In addition to this technique. If you make use of the class with a specific signature, you can refactor to get visual studio to generate the constructor for you. Also if this is a default constructor and you are not doing anything with it, then it is assumed to be there by default.
                              – James
                              Jul 15 '12 at 10:49




                              In addition to this technique. If you make use of the class with a specific signature, you can refactor to get visual studio to generate the constructor for you. Also if this is a default constructor and you are not doing anything with it, then it is assumed to be there by default.
                              – James
                              Jul 15 '12 at 10:49




                              1




                              1




                              Once or twice is a setting thing. I had this issue with a 1-letter-snippet and changed some (IntelliSense) settings to make 1 Tab work. ctor works for me with 1 hit though.
                              – Bitterblue
                              Mar 3 '14 at 7:54






                              Once or twice is a setting thing. I had this issue with a 1-letter-snippet and changed some (IntelliSense) settings to make 1 Tab work. ctor works for me with 1 hit though.
                              – Bitterblue
                              Mar 3 '14 at 7:54














                              up vote
                              19
                              down vote













                              If you want to see the list of all available snippets:



                              Press Ctrl + K and then X.






                              share|improve this answer



























                                up vote
                                19
                                down vote













                                If you want to see the list of all available snippets:



                                Press Ctrl + K and then X.






                                share|improve this answer

























                                  up vote
                                  19
                                  down vote










                                  up vote
                                  19
                                  down vote









                                  If you want to see the list of all available snippets:



                                  Press Ctrl + K and then X.






                                  share|improve this answer














                                  If you want to see the list of all available snippets:



                                  Press Ctrl + K and then X.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Sep 26 at 19:21









                                  Peter Mortensen

                                  13.3k1983111




                                  13.3k1983111










                                  answered May 28 '15 at 7:23









                                  ANewGuyInTown

                                  1,96111116




                                  1,96111116






















                                      up vote
                                      6
                                      down vote













                                      Type ctor, and then press TAB twice.






                                      share|improve this answer



























                                        up vote
                                        6
                                        down vote













                                        Type ctor, and then press TAB twice.






                                        share|improve this answer

























                                          up vote
                                          6
                                          down vote










                                          up vote
                                          6
                                          down vote









                                          Type ctor, and then press TAB twice.






                                          share|improve this answer














                                          Type ctor, and then press TAB twice.







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Sep 26 at 18:55









                                          Peter Mortensen

                                          13.3k1983111




                                          13.3k1983111










                                          answered Oct 28 '14 at 11:00









                                          ssmsnet

                                          8962912




                                          8962912






















                                              up vote
                                              5
                                              down vote













                                              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






                                              share|improve this answer



























                                                up vote
                                                5
                                                down vote













                                                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






                                                share|improve this answer

























                                                  up vote
                                                  5
                                                  down vote










                                                  up vote
                                                  5
                                                  down vote









                                                  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






                                                  share|improve this answer














                                                  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







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Jul 24 '15 at 7:11

























                                                  answered Jul 14 '15 at 10:41









                                                  Marleen Schilt

                                                  6081323




                                                  6081323






















                                                      up vote
                                                      4
                                                      down vote













                                                      In Visual Studio 2010, if you type "ctor" (without the quotes), IntelliSense should load, showing you "ctor" in the list. Now press TAB twice, and you should have generated an empty constructor.






                                                      share|improve this answer



























                                                        up vote
                                                        4
                                                        down vote













                                                        In Visual Studio 2010, if you type "ctor" (without the quotes), IntelliSense should load, showing you "ctor" in the list. Now press TAB twice, and you should have generated an empty constructor.






                                                        share|improve this answer

























                                                          up vote
                                                          4
                                                          down vote










                                                          up vote
                                                          4
                                                          down vote









                                                          In Visual Studio 2010, if you type "ctor" (without the quotes), IntelliSense should load, showing you "ctor" in the list. Now press TAB twice, and you should have generated an empty constructor.






                                                          share|improve this answer














                                                          In Visual Studio 2010, if you type "ctor" (without the quotes), IntelliSense should load, showing you "ctor" in the list. Now press TAB twice, and you should have generated an empty constructor.







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Sep 26 at 18:53









                                                          Peter Mortensen

                                                          13.3k1983111




                                                          13.3k1983111










                                                          answered Feb 4 '13 at 17:07









                                                          Sifou13

                                                          30623




                                                          30623






















                                                              up vote
                                                              3
                                                              down vote













                                                              Simply type ctor then press TAB.






                                                              share|improve this answer



























                                                                up vote
                                                                3
                                                                down vote













                                                                Simply type ctor then press TAB.






                                                                share|improve this answer

























                                                                  up vote
                                                                  3
                                                                  down vote










                                                                  up vote
                                                                  3
                                                                  down vote









                                                                  Simply type ctor then press TAB.






                                                                  share|improve this answer














                                                                  Simply type ctor then press TAB.







                                                                  share|improve this answer














                                                                  share|improve this answer



                                                                  share|improve this answer








                                                                  edited Jul 14 '15 at 12:33









                                                                  Marleen Schilt

                                                                  6081323




                                                                  6081323










                                                                  answered Oct 6 '10 at 14:46









                                                                  Oded

                                                                  405k70731899




                                                                  405k70731899






















                                                                      up vote
                                                                      3
                                                                      down vote













                                                                      Type ctor, and then press the Tab key.






                                                                      share|improve this answer



























                                                                        up vote
                                                                        3
                                                                        down vote













                                                                        Type ctor, and then press the Tab key.






                                                                        share|improve this answer

























                                                                          up vote
                                                                          3
                                                                          down vote










                                                                          up vote
                                                                          3
                                                                          down vote









                                                                          Type ctor, and then press the Tab key.






                                                                          share|improve this answer














                                                                          Type ctor, and then press the Tab key.







                                                                          share|improve this answer














                                                                          share|improve this answer



                                                                          share|improve this answer








                                                                          edited Sep 26 at 18:48









                                                                          Peter Mortensen

                                                                          13.3k1983111




                                                                          13.3k1983111










                                                                          answered Oct 6 '10 at 14:49









                                                                          MuhammadHani

                                                                          6,36342344




                                                                          6,36342344






















                                                                              up vote
                                                                              3
                                                                              down vote













                                                                              Type ctor and Tab.



                                                                              ََََََََََ






                                                                              share|improve this answer



























                                                                                up vote
                                                                                3
                                                                                down vote













                                                                                Type ctor and Tab.



                                                                                ََََََََََ






                                                                                share|improve this answer

























                                                                                  up vote
                                                                                  3
                                                                                  down vote










                                                                                  up vote
                                                                                  3
                                                                                  down vote









                                                                                  Type ctor and Tab.



                                                                                  ََََََََََ






                                                                                  share|improve this answer














                                                                                  Type ctor and Tab.



                                                                                  ََََََََََ







                                                                                  share|improve this answer














                                                                                  share|improve this answer



                                                                                  share|improve this answer








                                                                                  edited Sep 26 at 18:50









                                                                                  Peter Mortensen

                                                                                  13.3k1983111




                                                                                  13.3k1983111










                                                                                  answered Oct 11 '12 at 16:30









                                                                                  Jay

                                                                                  528




                                                                                  528






















                                                                                      up vote
                                                                                      2
                                                                                      down vote













                                                                                      I don't know about Visual Studio 2010, but in Visual Studio 2008 the code snippet is 'ctor'.






                                                                                      share|improve this answer























                                                                                      • It is the same for vs-2008 and vs-2008, and I think is also the same for vs-2005 but not 100% sure.
                                                                                        – Amra
                                                                                        Oct 6 '10 at 14:48















                                                                                      up vote
                                                                                      2
                                                                                      down vote













                                                                                      I don't know about Visual Studio 2010, but in Visual Studio 2008 the code snippet is 'ctor'.






                                                                                      share|improve this answer























                                                                                      • It is the same for vs-2008 and vs-2008, and I think is also the same for vs-2005 but not 100% sure.
                                                                                        – Amra
                                                                                        Oct 6 '10 at 14:48













                                                                                      up vote
                                                                                      2
                                                                                      down vote










                                                                                      up vote
                                                                                      2
                                                                                      down vote









                                                                                      I don't know about Visual Studio 2010, but in Visual Studio 2008 the code snippet is 'ctor'.






                                                                                      share|improve this answer














                                                                                      I don't know about Visual Studio 2010, but in Visual Studio 2008 the code snippet is 'ctor'.







                                                                                      share|improve this answer














                                                                                      share|improve this answer



                                                                                      share|improve this answer








                                                                                      edited Sep 26 at 18:24









                                                                                      Peter Mortensen

                                                                                      13.3k1983111




                                                                                      13.3k1983111










                                                                                      answered Oct 6 '10 at 14:46









                                                                                      M_J_O_N_E_S

                                                                                      563




                                                                                      563












                                                                                      • It is the same for vs-2008 and vs-2008, and I think is also the same for vs-2005 but not 100% sure.
                                                                                        – Amra
                                                                                        Oct 6 '10 at 14:48


















                                                                                      • It is the same for vs-2008 and vs-2008, and I think is also the same for vs-2005 but not 100% sure.
                                                                                        – Amra
                                                                                        Oct 6 '10 at 14:48
















                                                                                      It is the same for vs-2008 and vs-2008, and I think is also the same for vs-2005 but not 100% sure.
                                                                                      – Amra
                                                                                      Oct 6 '10 at 14:48




                                                                                      It is the same for vs-2008 and vs-2008, and I think is also the same for vs-2005 but not 100% sure.
                                                                                      – Amra
                                                                                      Oct 6 '10 at 14:48










                                                                                      up vote
                                                                                      2
                                                                                      down vote













                                                                                      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'.






                                                                                      share|improve this answer



























                                                                                        up vote
                                                                                        2
                                                                                        down vote













                                                                                        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'.






                                                                                        share|improve this answer

























                                                                                          up vote
                                                                                          2
                                                                                          down vote










                                                                                          up vote
                                                                                          2
                                                                                          down vote









                                                                                          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'.






                                                                                          share|improve this answer














                                                                                          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'.







                                                                                          share|improve this answer














                                                                                          share|improve this answer



                                                                                          share|improve this answer








                                                                                          edited Sep 26 at 18:55









                                                                                          Peter Mortensen

                                                                                          13.3k1983111




                                                                                          13.3k1983111










                                                                                          answered Jun 5 '13 at 9:29









                                                                                          denish

                                                                                          211




                                                                                          211






















                                                                                              up vote
                                                                                              1
                                                                                              down vote













                                                                                              For Visual Studio 2017 press "Ctrl + ."






                                                                                              share|improve this answer

















                                                                                              • 1




                                                                                                It doesn't work for generating a constructor.
                                                                                                – azish
                                                                                                Aug 24 at 12:04






                                                                                              • 1




                                                                                                I tried and it's working.. Please read this link docs.microsoft.com/en-us/visualstudio/ide/reference/…
                                                                                                – sadrag
                                                                                                Aug 24 at 12:25















                                                                                              up vote
                                                                                              1
                                                                                              down vote













                                                                                              For Visual Studio 2017 press "Ctrl + ."






                                                                                              share|improve this answer

















                                                                                              • 1




                                                                                                It doesn't work for generating a constructor.
                                                                                                – azish
                                                                                                Aug 24 at 12:04






                                                                                              • 1




                                                                                                I tried and it's working.. Please read this link docs.microsoft.com/en-us/visualstudio/ide/reference/…
                                                                                                – sadrag
                                                                                                Aug 24 at 12:25













                                                                                              up vote
                                                                                              1
                                                                                              down vote










                                                                                              up vote
                                                                                              1
                                                                                              down vote









                                                                                              For Visual Studio 2017 press "Ctrl + ."






                                                                                              share|improve this answer












                                                                                              For Visual Studio 2017 press "Ctrl + ."







                                                                                              share|improve this answer












                                                                                              share|improve this answer



                                                                                              share|improve this answer










                                                                                              answered Oct 20 '17 at 12:21









                                                                                              sadrag

                                                                                              618




                                                                                              618








                                                                                              • 1




                                                                                                It doesn't work for generating a constructor.
                                                                                                – azish
                                                                                                Aug 24 at 12:04






                                                                                              • 1




                                                                                                I tried and it's working.. Please read this link docs.microsoft.com/en-us/visualstudio/ide/reference/…
                                                                                                – sadrag
                                                                                                Aug 24 at 12:25














                                                                                              • 1




                                                                                                It doesn't work for generating a constructor.
                                                                                                – azish
                                                                                                Aug 24 at 12:04






                                                                                              • 1




                                                                                                I tried and it's working.. Please read this link docs.microsoft.com/en-us/visualstudio/ide/reference/…
                                                                                                – sadrag
                                                                                                Aug 24 at 12:25








                                                                                              1




                                                                                              1




                                                                                              It doesn't work for generating a constructor.
                                                                                              – azish
                                                                                              Aug 24 at 12:04




                                                                                              It doesn't work for generating a constructor.
                                                                                              – azish
                                                                                              Aug 24 at 12:04




                                                                                              1




                                                                                              1




                                                                                              I tried and it's working.. Please read this link docs.microsoft.com/en-us/visualstudio/ide/reference/…
                                                                                              – sadrag
                                                                                              Aug 24 at 12:25




                                                                                              I tried and it's working.. Please read this link docs.microsoft.com/en-us/visualstudio/ide/reference/…
                                                                                              – sadrag
                                                                                              Aug 24 at 12:25










                                                                                              up vote
                                                                                              1
                                                                                              down vote













                                                                                              Should you be interested in creating the 'ctor' or a similar class-name-injecting snippet from scratch, create a .snippet file in the C# snippets directory (for example C:VS2017VC#Snippets1033Visual C#C#Snippets.snippet) with this XML content:



                                                                                              <CodeSnippets>
                                                                                              <CodeSnippet>
                                                                                              <Header>
                                                                                              <Title>ctor</Title>
                                                                                              <Shortcut>ctor</Shortcut>
                                                                                              </Header>
                                                                                              <Snippet>
                                                                                              <Declarations>
                                                                                              <Literal Editable="false"><ID>classname</ID><Function>ClassName()</Function></Literal>
                                                                                              </Declarations>
                                                                                              <Code>
                                                                                              <![CDATA[public $classname$($end$)
                                                                                              {

                                                                                              }]]>
                                                                                              </Code>
                                                                                              </Snippet>
                                                                                              </CodeSnippet>
                                                                                              </CodeSnippets>


                                                                                              This snippet injects the current class name by way of calling C# code snippet function ClassName(), detailed on this docs.microsoft page.



                                                                                              The end result of expanding this code snippet:



                                                                                              'ctor' snippet



                                                                                              Constructor end result






                                                                                              share|improve this answer



























                                                                                                up vote
                                                                                                1
                                                                                                down vote













                                                                                                Should you be interested in creating the 'ctor' or a similar class-name-injecting snippet from scratch, create a .snippet file in the C# snippets directory (for example C:VS2017VC#Snippets1033Visual C#C#Snippets.snippet) with this XML content:



                                                                                                <CodeSnippets>
                                                                                                <CodeSnippet>
                                                                                                <Header>
                                                                                                <Title>ctor</Title>
                                                                                                <Shortcut>ctor</Shortcut>
                                                                                                </Header>
                                                                                                <Snippet>
                                                                                                <Declarations>
                                                                                                <Literal Editable="false"><ID>classname</ID><Function>ClassName()</Function></Literal>
                                                                                                </Declarations>
                                                                                                <Code>
                                                                                                <![CDATA[public $classname$($end$)
                                                                                                {

                                                                                                }]]>
                                                                                                </Code>
                                                                                                </Snippet>
                                                                                                </CodeSnippet>
                                                                                                </CodeSnippets>


                                                                                                This snippet injects the current class name by way of calling C# code snippet function ClassName(), detailed on this docs.microsoft page.



                                                                                                The end result of expanding this code snippet:



                                                                                                'ctor' snippet



                                                                                                Constructor end result






                                                                                                share|improve this answer

























                                                                                                  up vote
                                                                                                  1
                                                                                                  down vote










                                                                                                  up vote
                                                                                                  1
                                                                                                  down vote









                                                                                                  Should you be interested in creating the 'ctor' or a similar class-name-injecting snippet from scratch, create a .snippet file in the C# snippets directory (for example C:VS2017VC#Snippets1033Visual C#C#Snippets.snippet) with this XML content:



                                                                                                  <CodeSnippets>
                                                                                                  <CodeSnippet>
                                                                                                  <Header>
                                                                                                  <Title>ctor</Title>
                                                                                                  <Shortcut>ctor</Shortcut>
                                                                                                  </Header>
                                                                                                  <Snippet>
                                                                                                  <Declarations>
                                                                                                  <Literal Editable="false"><ID>classname</ID><Function>ClassName()</Function></Literal>
                                                                                                  </Declarations>
                                                                                                  <Code>
                                                                                                  <![CDATA[public $classname$($end$)
                                                                                                  {

                                                                                                  }]]>
                                                                                                  </Code>
                                                                                                  </Snippet>
                                                                                                  </CodeSnippet>
                                                                                                  </CodeSnippets>


                                                                                                  This snippet injects the current class name by way of calling C# code snippet function ClassName(), detailed on this docs.microsoft page.



                                                                                                  The end result of expanding this code snippet:



                                                                                                  'ctor' snippet



                                                                                                  Constructor end result






                                                                                                  share|improve this answer














                                                                                                  Should you be interested in creating the 'ctor' or a similar class-name-injecting snippet from scratch, create a .snippet file in the C# snippets directory (for example C:VS2017VC#Snippets1033Visual C#C#Snippets.snippet) with this XML content:



                                                                                                  <CodeSnippets>
                                                                                                  <CodeSnippet>
                                                                                                  <Header>
                                                                                                  <Title>ctor</Title>
                                                                                                  <Shortcut>ctor</Shortcut>
                                                                                                  </Header>
                                                                                                  <Snippet>
                                                                                                  <Declarations>
                                                                                                  <Literal Editable="false"><ID>classname</ID><Function>ClassName()</Function></Literal>
                                                                                                  </Declarations>
                                                                                                  <Code>
                                                                                                  <![CDATA[public $classname$($end$)
                                                                                                  {

                                                                                                  }]]>
                                                                                                  </Code>
                                                                                                  </Snippet>
                                                                                                  </CodeSnippet>
                                                                                                  </CodeSnippets>


                                                                                                  This snippet injects the current class name by way of calling C# code snippet function ClassName(), detailed on this docs.microsoft page.



                                                                                                  The end result of expanding this code snippet:



                                                                                                  'ctor' snippet



                                                                                                  Constructor end result







                                                                                                  share|improve this answer














                                                                                                  share|improve this answer



                                                                                                  share|improve this answer








                                                                                                  edited Sep 26 at 19:23









                                                                                                  Peter Mortensen

                                                                                                  13.3k1983111




                                                                                                  13.3k1983111










                                                                                                  answered Sep 6 '17 at 14:57









                                                                                                  Neil Justice

                                                                                                  5742621




                                                                                                  5742621






















                                                                                                      up vote
                                                                                                      0
                                                                                                      down vote













                                                                                                      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.






                                                                                                      share|improve this answer

























                                                                                                        up vote
                                                                                                        0
                                                                                                        down vote













                                                                                                        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.






                                                                                                        share|improve this answer























                                                                                                          up vote
                                                                                                          0
                                                                                                          down vote










                                                                                                          up vote
                                                                                                          0
                                                                                                          down vote









                                                                                                          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.






                                                                                                          share|improve this answer












                                                                                                          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.







                                                                                                          share|improve this answer












                                                                                                          share|improve this answer



                                                                                                          share|improve this answer










                                                                                                          answered Nov 10 at 19:14









                                                                                                          nuwanjaya

                                                                                                          118111




                                                                                                          118111






























                                                                                                               

                                                                                                              draft saved


                                                                                                              draft discarded



















































                                                                                                               


                                                                                                              draft saved


                                                                                                              draft discarded














                                                                                                              StackExchange.ready(
                                                                                                              function () {
                                                                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3873702%2fcode-snippet-or-short-cut-to-create-a-constructor-in-visual-studio%23new-answer', 'question_page');
                                                                                                              }
                                                                                                              );

                                                                                                              Post as a guest















                                                                                                              Required, but never shown





















































                                                                                                              Required, but never shown














                                                                                                              Required, but never shown












                                                                                                              Required, but never shown







                                                                                                              Required, but never shown

































                                                                                                              Required, but never shown














                                                                                                              Required, but never shown












                                                                                                              Required, but never shown







                                                                                                              Required, but never shown







                                                                                                              Popular posts from this blog

                                                                                                              Full-time equivalent

                                                                                                              さくらももこ

                                                                                                              13 indicted, 8 arrested in Calif. drug cartel investigation