How to quickly add code snippets in Visual Studio

Source: Internet
Author: User
Tags exception handling serialization

Just know, type prop, and then press two times the TAB key to generate the automatic property code.

Having nothing to do today, I sorted out other quick ways to add code snippets in Visual Studio.

1. Automatic Properties

Type prop, and then press two times the TAB key to generate the automatic property code.

public int MyProperty {get; set;}

Through the experiment found that input pr,pro,proc, and then press two times the TAB key, the same will generate automatic property code snippets.

2.class

Type class, and then press the TAB key two times to generate the definition code.

Class MyClass
{
}

3.interface

Type interface, and then press two times the TAB key to generate the interface definition code.

Interface IInterface
{
}

4.struct

Type struct, and then press two times the TAB key to generate the structure definition code.

struct mystruct
{
}

5.for

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

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

6.foreach

Type foreach, and then press the TAB key two times to generate the Foreach Loop code.

foreach (var item in collection)
{
}

7.while

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

while (true)
{
}

8.do-while

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

Do
 {        
 } (TRUE);

10.try-catch

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

Try 
{	        
}
catch (Exception)
{
   throw
}

11.if statement

Type if, and then press two times the TAB key to generate the conditional statement code.

if (true)
{
}

12.enum

Type an enum, and then press the TAB key two times to generate an enumeration definition code.

Enum MyEnum
{
}

13.namespace

Type namespace, and then press two times the TAB key to generate the namespace code.

Namespace MyNamespace
{
}

14.switch

The branch code is generated by typing the switch and then pressing the TAB key two times.

Switch (switch_on)
{
    default:

Exception

Type exception, and then press the TAB key two times to generate the following code.

[Global::system.serializable]
public class Myexception:exception
{public
  myexception () {} public
  MyException (String message): Base ( Message] {} public
  MyException (string message, Exception inner): base (message, inner) {}
  protected Myexc Eption ( 
  System.Runtime.Serialization.SerializationInfo info, 
  System.Runtime.Serialization.StreamingContext context): Base (info, context) {}
}

16 Dependent Properties

Type propdb, and then press two times the TAB key to generate the dependency property definition code.















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.