枚举类型如下:
public enum ConcertCode
{
BEIJING,
SHANGHAI,
GUANGZHOU
}
如果要将比如“beijing”字符串转换为ConcertCode.BEIJING的话,可以通过如下方法:
ConcertCode c = (ConcertCode)Enum.Parse(typeof(ConcertCode), 字符串的变量, true);
很容易吧,呵呵。。于是呼,我的问题也就解决了:
(Keys)Enum.Parse(typeof(Keys), hotkey_2, true)
(注:keys为System.Windows.Forms.Keys的枚举变量,hotkey_2是我定义的字符串变量)
详细解决方案
字符串转枚举类型
热度:1 发布时间:2024-01-22 03:09:32.0
相关解决方案