VS中常用C#代码段快速输入

Visual Studio 中有很多代码段都可以直接简写然后按TAB快速输入编译器中,为了提高编程效率,特此查阅资料,罗列总结。

 1.       ~              创建析构函数

              ~Program()

                    {

                    }

 2.     checked                       创建checked

            checked

               {                    

               }

 3.     class             创建类声明

       classMyClass

               {               

               }

 4.            ctor              创建对应类的构造函数

  public Program ()

                 {

                 }

 5.     cw               创建对Console.WriteLine();的调用

       Console.WriteLine();

 6.      do                创建do(while)循环

       do

            {               

            } while (true);

 7.    else               创建else

          else

                {

                }

 8.    enum              创建enum声明

         enumMyEnum

                    {            

                    }

 9.    for                创建for循环

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

               {               

               }

 10.   foreach             创建foreach循环

        foreach (var itemin collection)

                {               

                }

var        代表要循环访问的集合中对象的类型

item       表示集合中的元素的标示符

collection   要循环访问的集合或数组的名称

 11.   forr   创建for循环,在每次循环后递减循环变量

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

            {               

            }

 12.    if     创建if

        if (true)

            {               

            }

 13.   interface     创建interface声明

 interfaceIInterface

                          {               

                           }

          IInterface    代表接口名称

 14.   lock        创建lock

       lock (this)

               {                

                }

    this    代表表达式

 15.    namespace    创建namespace声明

        namespace MyNamespace

                           {               

                           }

 16.    prop          创建属性代码块

       publicint MyProperty {get;set; }

          

 17.   struct          创建struct声明

                       struct MyStruct

                                    {               

                                    }

 18.   svm           创建static viod声明

                    staticvoid Main(string[] args)

{

}

 19.   switch         创建switch代码块

                                 switch (switch_on)

                             {

                                    default:

  }

   switch_on        代表条件表达式

 20.   try             创建try-catch代码块

        try

            {

            }

            catch (Exception)

            {               

                throw;

            }

  21.   unchecked       创建unchecked代码块

                 unchecked

            {

            }

  22.   unsafe        创建unsafe代码块

 

unsafe

                  {

        }

  23.   using          创建using指令

       using (resource)

            {               

            }

        resource为要使用的资源

  24.   while          创建while循环

          while (true)

            {                

            }

  true可替换为运算结果为bool类型的表达式。

如上属于visual studio 中常用的C#代码段简写,我们还可以通过在VC#\Snippets\2052\Visual C#中添加.snippet文件,

编写自定义的C#代码段,具体方法,待以后学会后再做总结:-D

---------------------------------------------------------

2013-12-12 补充:

自定义代码段方法链接:VS中自定义代码段

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值