c#中Enum和String相互转换

时间:2015-02-01 20:31:55   收藏:0   阅读:194

枚举:

 public enum MonitorType
        {
            ManualMonitor ,//人工监测
            Tm30,//TM机器人监测
            Ls ,//拉载监测
            FiberBraggGrate,//光纤光栅
            LightMonitor,//微光监测
            Gps //GPS监测

        }

String转Enum:

MonitorType monitorType = (MonitorType)Enum.Parse(typeof(MonitorType), "Ls");

Enum转String:


String  str=MonitorType.Ls.toString();



评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!