天天看點

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 補充: