• 【转】在Visual Studio中怎样快速添加代码段


    原文网址:http://blog.csdn.net/yl2isoft/article/details/9735527

    以前一直只知道,键入prop,再按两次tab键,会生成自动属性代码。

    今天闲着无事,就整理了一下在Visual Studio中其他快速添加代码段的方法。

    1.自动属性

    键入prop,再按两次tab键,会生成自动属性代码。

    [csharp] view plaincopy
     
    1. public int MyProperty { get; set; }  

    通过实验发现,输入pr,pro,proc等,再按两次tab键,同样会生成自动属性代码段。

    2.class

    键入class,再按两次tab键,会生成类定义代码。

    [csharp] view plaincopy
     
    1. class MyClass  
    2. {  
    3. }  

    3.interface

    键入interface,再按两次tab键,会生成接口定义代码。

    [csharp] view plaincopy
     
    1. interface IInterface  
    2. {  
    3. }  

    4.struct

    键入struct,再按两次tab键,会生成结构体定义代码。

    [csharp] view plaincopy
     
    1. struct MyStruct  
    2. {  
    3. }  

    5.for

    键入for,再按两次tab键,会生成for循环代码。

    [csharp] view plaincopy
     
    1. for (int i = 0; i < length; i++)  
    2. {  
    3. }  

    6.foreach

    键入foreach,再按两次tab键,会生成foreach循环代码。

    [csharp] view plaincopy
     
    1. foreach (var item in collection)  
    2. {  
    3. }  

    7.while

    键入while,再按两次tab键,会生成while循环代码。

    [csharp] view plaincopy
     
    1. while (true)  
    2. {  
    3. }  

    8.do-while

    键入do,再按两次tab键,会生成do-while循环代码。

    [csharp] view plaincopy
     
    1. do  
    2.  {          
    3.  } while (true);  

    10.try-catch

    键入try,再按两次tab键,会生成异常处理代码。

    [csharp] view plaincopy
     
    1. try   
    2. {             
    3. }  
    4. catch (Exception)  
    5. {  
    6.    throw;  
    7. }  

    11.if语句

    键入if,再按两次tab键,会生成条件语句代码。

    [csharp] view plaincopy
     
    1. if (true)  
    2. {  
    3. }  

    12.enum

    键入enum,再按两次tab键,会生成枚举定义代码。

    [csharp] view plaincopy
     
    1. enum MyEnum  
    2. {  
    3. }  

    13.namespace

    键入namespace,再按两次tab键,会生成命名空间代码。

    [csharp] view plaincopy
     
    1. namespace MyNamespace  
    2. {  
    3. }  

    14.switch

    键入switch,再按两次tab键,会生成分支代码。

    [csharp] view plaincopy
     
    1. switch (switch_on)  
    2. {  
    3.     default:  
    4. }   

    15 Exception

    键入Exception,再按两次tab键,会生成如下代码。

    [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. }  
  • 相关阅读:
    WeihanLi.Npoi 1.10.0 更新日志
    消除代码中的坏味道,编写高质量代码
    代码重构之法——方法重构分析
    使用 C# 捕获进程输出
    .net core 中的经典设计模式的应用
    JDBC 规范中文版 4.2 -第一章 简介
    基础回顾-线程的几种状态
    一文读懂BeanFactory和FactoryBean区别
    阿里云云计算ACA 第三章 阿里云存储服务
    阿里云云计算ACA 第二章 阿里云弹性计算
  • 原文地址:https://www.cnblogs.com/wi100sh/p/4210346.html
Copyright © 2020-2023  润新知