最好的辦法可以說我有一個枚舉的定義,像這樣:是什麼標籤附加到枚舉值
public enum eCommentType
{
NormalComment = 0,
OpenningComment = 1,
StartProgressCommetn = 2,
ClouserComment = 3,
ReopennignComment = 4
}
現在我想提出一個網頁上的enum
選項。 我可以只使用switch
語句,但是當我添加一個新的值時,我將不得不更新我的switch語句。 什麼是最好的方式追加一個標籤到每個值或事件更好的資源ID來支持多語言界面?
P.S 我使用MVC爲我當前的項目,但我將不勝感激一個普遍的答案,可以用於多種技術,即設計模式。
'DescriptionAttribute'文本? http://blogs.msdn.com/b/paulwhit/archive/2008/03/31/use-the-descriptionattribute-with-an-enum-to-display-status-messages.aspx –
http:// stackoverflow。 com/questions/12403065/how-can-i-assign-a-string-to-an-enum-instead-of-an-integer-value-in-c/12403191#12403191 – Habib
請停止提及「ASP。 NET MVC「簡稱爲」MVC「。一個是框架,而另一個是獨立於語言的設計模式。這就像打電話給IE - 「互聯網」 –