[C#] C# 初學筆記 (1)

  1. using System;
  2. namespace ConsoleApplication1
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             Console.WriteLine("Hello Word");
  9.             Console.WriteLine("fora = " + (int)ExEnum.fora);
  10.             Console.WriteLine("forb = "+(int)ExEnum.forb);
  11.             //這是註解
  12.             /*這也
  13.               是註解*/
  14.         }
  15.         enum ExEnum:int
  16.         {
  17.             fora = 1,
  18.             forb = 5,
  19.         }
  20.     }
  21. }


第1行:using 是用來使用命名空間裡面的類別
第2行:namespace 是用來定義這個範例裡面命名空間的有效範圍
第6行:Main()方法是程式進入點
第8~10行:印出內容
第11~13行:註解的方法
第15行:用enum xxx { ooo }定義列舉,裡面的內容是將類別成員初始化為常數 (ps1)

Class若不傳回任何值:

  1. static void Main(){
  2.     .....;
  3. }

Class若傳回一個整數:

  1. static int Main(){
  2.     .....;
  3.     return 0;
  4. }

Class可以接受外來輸入的引數:

  1. static void Main(string[] args){
  2.     .....
  3. }

Ps1.
enum 可以在前面加上修飾詞(public, protected, private, internal)來指定有效存取範圍,後面也可以定義資料型別(base-type , 預設為int , 可為byte, long , short……等),enum的用法為

  1. 修飾詞 enum enum名稱 : base-type
  2. {
  3.     列舉內容........
  4. }

0個對 “[C#] C# 初學筆記 (1)” 的回應


  • 無評論

留下回覆