C#基础 [02] C#程序的通用结构

 一、概述

  《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 YourNamespace
12 {
13     //
14     class YourClass
15     {
16         int _age;
17 
18         public int Age
19         {
20             get { return _age; }
21             set { _age = value; }
22         }
23 
24     }
25 
26     // 结构
27     struct YourStruct
28     {
29     }
30 
31     // 接口
32     interface IYourInterface
33     {
34     }
35 
36     // 委托
37     delegate int YourDelegate();
38 
39     // 枚举
40     enum YourEnum
41     {
42     }
43 
44     // 内嵌的命名空间
45     namespace YourNestedNamespace
46     {
47         // 内嵌的结构
48         struct YourStruct
49         {
50         }
51     }
52 
53     class YourMainClass
54     {
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为成员。 
 
 
原文地址:https://www.cnblogs.com/sunyunh/p/2830168.html