下面帶有關鍵字的代碼工作正常,但我想像在 C# 中static一樣創建以下屬性。constant這樣做的原因是整個項目的一致性。所有值永遠不會改變的屬性都被標記為const不在static or static readonly現有項目中。public class StatusList{public static Dictionary<DownloadStatus, int> DownlodStatusList{ get { return new Dictionary<DownloadStatus, int>() { { DownloadStatus.Preview, (int)DownloadStatus.Preview }, { DownloadStatus.Active, (int)DownloadStatus.Active }, { DownloadStatus.Expired, (int)DownloadStatus.Expired }, { DownloadStatus.Inactive, (int)DownloadStatus.Inactive } }; }}}
2 回答

吃雞游戲
TA貢獻1829條經驗 獲得超7個贊
你不能。
static readonly
和之間存在差異const
,因為無論何時代碼引用 a const
,都會將其值const
直接烘焙到它被引用的位置。因此 aconst
只能是數字、布爾值、字符串或空值。
- 2 回答
- 0 關注
- 200 瀏覽
添加回答
舉報
0/150
提交
取消