C#通用結構

來源:互聯網
上載者:User

標籤:

一、概述

  《C#4.0圖解教程》中將C#程式描述為“一群組類型聲明”。這是與C和C++相比較的結果,也是C#最大的特點。而我們日常的編程,就是如何設計、組織和應用這些類型以及它們的成員,來完成我們的需求。

  一個C# 程式可由一個或多個檔案組成,而每個檔案都可以包含零個或零個以上的命名空間。  一個命名空間除了可包含其他命名空間外,還可包含類、結構、介面、枚舉、委託等類型。下面是一個MSDN給的通用樣本。

二、樣本

 1 using System; 2  3 namespace HelloWorld 4 { 5     class GeneralStructure 6     { 7     } 8 } 9 10 // A skeleton of a C# program 11 namespace YourNamespace12 {13     // 類14     class YourClass15     {16         int _age;17 18         public int Age19         {20             get { return _age; }21             set { _age = value; }22         }23 24     }25 26     // 結構27     struct YourStruct28     {29     }30 31     // 介面32     interface IYourInterface33     {34     }35 36     // 委託37     delegate int YourDelegate();38 39     // 枚舉40     enum YourEnum41     {42     }43 44     // 內嵌的命名空間45     namespace YourNestedNamespace46     {47         // 內嵌的結構48         struct YourStruct49         {50         }51     }52 53     class YourMainClass54     {55          static void Main(string[] args) 56          {57              Your program starts here...58          }59     }60 }

三、C#/.Net程式表徵圖

  在VS寫代碼,或者是在物件瀏覽器中查看程式,我們會看到各種表徵圖。下面我列出了常見的一些表徵圖的樣本以及它所代表的含義。

    1.   assembly , 程式集
    2. namespace,命名空間
    3. class,類
    4. interface,介面
    5. struct,結構
    6. enum,枚舉
    7. delegate,委託
    8. method,公用方法
    9. protected method,受保護的方法
    10. property,公用屬性
    11.  field ,公用欄位
    其中3-7為類型,8-11為成員。 

C#通用結構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.