Enum、int、string之間的快速轉換

在項目中常常會使用枚舉類型,而在不一樣的地方須要使用不一樣的類型,好比:Enum、int、string之間的快速轉換。html

複製代碼
public enum Color {

    Red=1,     
   Green=2

}
複製代碼


(1)Enum轉換爲Stringpost

Color.Read.ToString()
Convert.ToString(Color.Green)

(2)Enum轉換爲intthis

Convert.ToInt32(Color.Green)

(a)String轉換爲Enumspa

 (Color)Enum.Parse(typeof(Color), "Red");


(b)Int轉換爲Numcode

(Color)1

 

 

出處:https://www.cnblogs.com/mqingqing123/p/8456242.htmlhtm

相關文章
相關標籤/搜索