# 初階Coding Style # 1.c#三大特性 (1)跨平台 (2)強型別 (3)物件導向:物件導向程式設計是種具有物件概念的程式程式設計典範,同時也是一種程式開發的抽象方針。它可能包含資料、屬性、程式碼與方法。物件則指的是類別的實例。它將物件作為程式的基本單元,將程式和資料封裝其中,以提高軟體的重用性、靈活性和擴充性,物件裡的程式可以存取及經常修改物件相關連的資料。 # 2.內置型別 使用C#內置型別,而非.NET Class library 用short 非System.Int16 用int 非System.Int32 用long 非System.Int64 用string 非 System.String # 3.方案結構 方案 →專案 →組件 →命名空間 →cs檔 →類別 →類別成員 # 4.檔案限制 一個cs檔只放一個類,除了巢狀類別、POCO(允許)、Partial(禁用) # 5.類別成員 (1)欄位 用private (2)屬性 可存取 用 (3)常數 (4)方法 # 6.存取修飾字 - [public](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/public): The type or member can be accessed by any other code in the same assembly or another assembly that references it. - [private](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/private): The type or member can be accessed only by code in the same `class` or `struct`. - [protected](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/protected): The type or member can be accessed only by code in the same `class`, or in a `class` that is derived from that `class`. - [internal](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/internal): The type or member can be accessed by any code in the same assembly(組件), but not from another assembly. - [protected internal](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/protected-internal): The type or member can be accessed by any code in the assembly in which it's declared, or from within a derived `class` in another assembly. - [private protected](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/private-protected): The type or member can be accessed only within its declaring assembly, by code in the same `class` or in a type that is derived from that `class`. [官方文件](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers) # 7.輸出類型 (1)Windows應用程式:WinForm類 (2)主控台應用程式:沒UI畫面,用console操控的 (3)類別庫:產出dll # 8.魔術數字 (1)列舉 (2)常數 (3)區域變數 # 9.命名規則 (1)常數→全大寫 (2)區域變數、方法參數→小寫開頭駝峰 (3)其餘→大寫開頭駝峰 (4)方法:以動詞開頭 (5)類別、類別成員:以名詞開頭 (6)bool:以Is Can Has…開頭 (7)只有方法內的區域變數可以使用temp這一類的通用暫時變數命名,禁止在類別級成員使用 (8)Interface的命名一律以I開頭,泛型的型別參數一律使用<T> # 10.空字串 空字串使用string.Empty # 11.工作清單 「檢視」→「工作清單」 (1)//TODO (2)//UNDONE (3)//HACK