需求:将config中配置好的一个string,赋值给程序中的某个枚举中的字段。
guarantee.guaranteeType
= (GuaranteeGuaranteeType)Enum.Parse(typeof(GuaranteeGuaranteeType), ConfigerFile.GuaranteeType, false);
= (GuaranteeGuaranteeType)Enum.Parse(typeof(GuaranteeGuaranteeType), ConfigerFile.GuaranteeType, false);
将配置的字符串ConfigerFile.GuaranteeType作为参数,找到GuaranteeGuaranteeType中匹配的枚举,并转换为(GuaranteeGuaranteeType)枚举类型。
注:Enum.Parse()第三个参数为是否区分大小写。
浙公网安备 33010602011771号