"Go" How to quickly add code snippets in Visual Studio

Source: Internet
Author: User

Original URL: http://blog.csdn.net/yl2isoft/article/details/9735527

I used to only know that, typing prop, and then pressing the TAB key two times, generates an automatic property code.

Today I have nothing to do, just sort of. Other ways to quickly add code snippets in Visual Studio.

1. Automatic attributes

Typing prop and pressing the TAB key two times generates an automatic property code.

[CSharp]View Plaincopy
    1. public int MyProperty { get;  set;}

Through the experiment found, input pr,pro,proc, and then press two times TAB key, will also generate automatic attribute code segment.

2.class

Typing class, and then pressing the TAB key two times, results in the definition code.

[CSharp]View Plaincopy
    1. Class MyClass
    2. {
    3. }

3.interface

Typing interface and pressing the TAB key two times will generate the interface definition code.

[CSharp]View Plaincopy
    1. Interface IInterface
    2. {
    3. }

4.struct

Type a struct, and then press two tab to generate the struct definition code.

[CSharp]View Plaincopy
    1. struct MYSTRUCT
    2. {
    3. }

5.for

Type for, and then press the TAB key two times to generate a for loop code.

[CSharp]View Plaincopy
    1. for (int i = 0; i < length; i++)
    2. {
    3. }

6.foreach

Typing foreach and pressing the TAB key two times generates a foreach Loop code.

[CSharp]View Plaincopy
    1. foreach (var item in Collection)
    2. {
    3. }

7.while

Typing while, and then pressing the TAB key two times, generates a while loop code.

[CSharp]View Plaincopy
    1. while (true)
    2. {
    3. }

8.do-while

Typing do, and then pressing the TAB key two times, generates the Do-while loop code.

[CSharp]View Plaincopy
    1. Do
    2. {
    3. } while (true);

10.try-catch

Typing the try, and then pressing the TAB key two times, generates exception handling code.

[CSharp]View Plaincopy
    1. Try
    2. {
    3. }
    4. catch (Exception)
    5. {
    6. throw;
    7. }

11.if statements

Typing if, and then pressing the TAB key two times, generates the conditional statement code.

[CSharp]View Plaincopy
    1. if (true)
    2. {
    3. }

12.enum

Typing an enum and pressing the TAB key two times will generate the enumeration definition code.

[CSharp]View Plaincopy
    1. Enum MyEnum
    2. {
    3. }

13.namespace

Typing namespace, and then pressing the TAB key two times, generates a namespace code.

[CSharp]View Plaincopy
    1. Namespace MyNamespace
    2. {
    3. }

14.switch

Typing switch and pressing the TAB key two times will generate the branch code.

[CSharp]View Plaincopy
    1. Switch (switch_on)
    2. {
    3. Default:
    4. }

Exception

Typing exception and pressing the TAB key two times will generate the following code.

[CSharp]View Plaincopy
  1. [Global::system.serializable]
  2. Public class Myexception:exception
  3. {
  4. Public myexception () {}
  5. Public myexception ( string message): base (Message) {}
  6. Public myexception ( string message, Exception inner): base (message, inner) {}
  7. protected MyException (
  8. System.Runtime.Serialization.SerializationInfo info,
  9. System.Runtime.Serialization.StreamingContext context): Base (info, context) {}
  10. }

"Go" How to quickly add code snippets in Visual Studio

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.