VS summarize quickly enter commonly used C # code snippet

Transfer: https: //blog.csdn.net/a980433875/article/details/12231673

Visual Studio has a lot of short code segment can be directly input and then press the TAB fast compiler in order to improve the efficiency of programming, is hereby access to information, a list summary.

 1. Create ~ destructor

              ~Program()

                    {

                    }

 2. checked create checked piece

            checked

               {                    

               }

 3. class create a class declaration

       classMyClass

               {               

               }

 4. ctor corresponding to the class constructor Create

  public Program ()

                 {

                 }

 5. cw creation of Console.WriteLine (); call

       Console.WriteLine();

 6. do create do (while) loop

       do

            {               

            } while (true);

 7. else created the else block

          else

                {

                }

 8. Create an enum enum declaration

         enumMyEnum

                    {            

                    }

 Create a for loop 9. for

        for (int i = 0; i < length; i++)

               {               

               }

 10. foreach create a foreach loop

        foreach (var itemin collection)

                {               

                }

Type represents a collection of objects to iterate var

Identifier item represents the set of elements

Name of the collection or array to iterate through the collection of

 11. forr create a for loop, the loop variable is decremented after each cycle

          for (int i = length - 1; i >= 0; i--)

            {               

            }

 12. The block if created if

        if (true)

            {               

            }

 13. interface to create interface statement

 interfaceIInterface

                          {               

                           }

          IInterface behalf interface name

 14. A lock block lock Creating

       lock (this)

               {                

                }

    this represents the expression

 15. namespace to create a namespace declaration

        namespace MyNamespace

                           {               

                           }

 Creating an attribute code blocks 16. prop

       publicint MyProperty {get;set; }

          

 17. struct create a struct declaration

                       struct MyStruct

                                    {               

                                    }

 18. Create svm static viod statement

                    staticvoid Main(string[] args)

{

}

 19. switch to create a block of code switch

                                 switch (switch_on)

                             {

                                    default:

  }

   switch_on on behalf of the conditional expression

 20. try to create try-catch block

        try

            {

            }

            catch (Exception)

            {               

                throw;

            }

  21. A unchecked code blocks created unchecked

                 unchecked

            {

            }

  22. unsafe create unsafe code blocks

 

unsafe

                  {

        }

  23. using created using instruction

       using (resource)

            {               

            }

        resource for the resource to be used

  24. while to create a while loop

          while (true)

            {                

            }

  Alternatively true for the result of the operation type bool expression.

As part of the commonly used C # code snippet abbreviated visual studio, we can also in VC # \ Snippets \ 2052 \ Visual C # add .snippet file

That is written in C # code snippets custom,

1, select "Tools", "snippet Manager"

     

 

 


2, the path of the copy position

        

 

 


3, win + r shortcut to open run, and then pasting position information of the transport


4, in this folder you can see the code snippet provided in the VS

 

 


5, a copy code segment to the desktop


6, with the open notebook                                         

    


7, modified snippet

 

 


8, and then rename the file into the folder (To format .snippet)

 First save on the desktop, the suffix changed, copied to the appropriate folder.

         


9, restart the IDE, shortcuts this time snippet can be used

       Seemingly without restarting the line.

 

 

 

 

summary:

 

 Although the setup code segment can facilitate, improve efficiency, but if you code proficiency is not enough, on the first


Do not often use.


  There problem is not terrible, terrible feeling no problem, but the problem a lot; identify problems in order to grow, Solve


The question will be stronger!

Guess you like

Origin www.cnblogs.com/BruceKing/p/11615037.html