[語法] C#與bcb語法的轉換

看板C_and_CPP作者 (bee)時間15年前 (2009/05/22 11:58), 編輯推噓1(106)
留言7則, 5人參與, 最新討論串1/2 (看更多)
最近想練習一個 Decorator pattern的程式, 在網上參考了別人的作品, 他的語言是C# 內中寫到 public virtual string Description { get { return description; } set { description = value; } } 想請問這段程式碼該怎麼改寫, 就我微薄的程式能力來看, 這似乎是在定義Description這個變數,是嗎? 很抱歉我基礎打不好,所以問題可能很瞎, 但我真的很想學,麻煩知道的人幫忙解答囉。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.126.200.190

05/22 12:12, , 1F
就是 getter 和 setter ,別想太多
05/22 12:12, 1F

05/22 13:10, , 2F
還是不會orz
05/22 13:10, 2F

05/22 13:14, , 3F
description =value 載入value的值之後回傳description
05/22 13:14, 3F

05/22 13:15, , 4F
小弟猜是這樣
05/22 13:15, 4F

05/22 13:47, , 5F
就 string getDescription(){return description;}
05/22 13:47, 5F

05/22 13:47, , 6F
void setDescription(string s){description = s;}
05/22 13:47, 6F

05/22 14:07, , 7F
樓上正解~
05/22 14:07, 7F
文章代碼(AID): #1A5YBiZ6 (C_and_CPP)
文章代碼(AID): #1A5YBiZ6 (C_and_CPP)