C# 常數變數宣告 const 與 readonly差別

 

const : 宣告時, 就要初始化, 之後就不能變更內容

const string MyConstantString = "Hello, I am a constant!";

readonly : 宣告後, 可以在程式執行期間(如建構子)初始化, 初始化後就不能變更內容

readonly string MyReadonlyString; public MyClass() { MyReadonlyString = "Hello, I am a readonly variable!"; }




留言

這個網誌中的熱門文章

ORA-12514: TNS: 監聽器目前不知道連線描述區中要求的服務

Oracle 例外控制(Exception Control)

Oracle 工作排程 DBMS_JOB 筆記