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

相关文章
相关标签/搜索