Type of conditional expression cannot be determined because there is no implicit conversion between 'Common.EnumType.EnumGender' and '<null>'

public EnumType.EnumGender? EmployeeGender
        {
            get { return (EnumType.EnumGender)_Model.EmployeeGender; }
            set { _Model.EmployeeGender = value != null ? (int)value : (int)EnumType.EnumGender.无限制;}
        }

今天用三元运算符给EmployeeGender赋值时,出现Type of conditional expression cannot be determined because there is no implicit conversion between 'char' and '<null>'错误

经查资料才明白,给EnumType.EnumGender赋值时必须对NULL进行转换,才可以.

代码如下:

bll.EmployeeGender=Request.Form["EmployeeGender"]!=""?(Common.EnumType.EnumGender)(int.Parse(Request.Form["EmployeeGender"])):(Common.EnumType.EnumGender?)null;

参考资料:http://social.msdn.microsoft.com/Forums/zh-TW/csharpgeneral/thread/506a8166-3113-4965-be51-d2a41f0fc01e

原文地址:https://www.cnblogs.com/cicada/p/2862789.html