日期:2014-05-20  浏览次数:20721 次

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