- using System;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Hello Word");
- Console.WriteLine("fora = " + (int)ExEnum.fora);
- Console.WriteLine("forb = "+(int)ExEnum.forb);
- //這是註解
- /*這也
- 是註解*/
- }
- enum ExEnum:int
- {
- fora = 1,
- forb = 5,
- }
- }
- }
第1行:using 是用來使用命名空間裡面的類別
第2行:namespace 是用來定義這個範例裡面命名空間的有效範圍
第6行:Main()方法是程式進入點
第8~10行:印出內容
第11~13行:註解的方法
第15行:用enum xxx { ooo }定義列舉,裡面的內容是將類別成員初始化為常數 (ps1)
Class若不傳回任何值:
- static void Main(){
- .....;
- }
Class若傳回一個整數:
- static int Main(){
- .....;
- return 0;
- }
Class可以接受外來輸入的引數:
- static void Main(string[] args){
- .....
- }
Ps1.
enum 可以在前面加上修飾詞(public, protected, private, internal)來指定有效存取範圍,後面也可以定義資料型別(base-type , 預設為int , 可為byte, long , short……等),enum的用法為
- 修飾詞 enum enum名稱 : base-type
- {
- 列舉內容........
- }
0個對 “[C#] C# 初學筆記 (1)” 的回應