首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

enum 不能从string 转换?解决办法

2012-01-05 
enum 不能从string 转换?publicvoidLoadPara(){RegistryKeyrkRegistry.LocalMachineRegistryKeyhklmrk.

enum 不能从string 转换?
public   void   LoadPara()
                {

                        RegistryKey   rk   =   Registry.LocalMachine;

                        RegistryKey   hklm   =   rk.CreateSubKey(RegRoot   +   ID.ToString());


                        commPort.PortName   =   (string)(hklm.GetValue( "PortName ", "COM1 "));

                        commPort.BaudRate   =   (int)(hklm.GetValue( "BaudRate ",   9600));

                        commPort.Parity   =   (Parity)(hklm.GetValue( "Parity ",Parity.None));

                        commPort.StopBits   =   (StopBits)(hklm.GetValue( "StopBits ",   StopBits.One));

                        hklm.Close();

                }

[解决办法]

Enum.Parse(typeof(Parity), hklm.GetValue( "Parity ",Parity.None));

---------------------------
http://pointlessly.blogspot.com

热点排行