运营商“??”不能应用于“System.DateTime”类型的操作数 [英] Operator '??' cannot be applied to operands of type 'System.DateTime'

查看:111
本文介绍了运营商“??”不能应用于“System.DateTime”类型的操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 运算符'??'不能用于'System.DateTime'类型的操作数, 






  foreach (EndServReward r奖励)
{
if(con.State == ConnectionState.Closed)
{
con.Open();
}
myIfxCmd.Parameters [0] .Value = r.EmpNum;
myIfxCmd.Parameters [1] .Value =(r.ServDate)?? DBNull.Value;






其中奖励是List< EndServReward>奖励,为什么发生这种情况,以及如何解决它?

是空合并运算符。

将它应用于不能为 null


I get the following error :

Operator '??' cannot be applied to operands of type 'System.DateTime'


 foreach (EndServReward r in reward)
                            {
                                if (con.State == ConnectionState.Closed)
                                {
                                    con.Open();
                                }
                                myIfxCmd.Parameters[0].Value = r.EmpNum ;
                                myIfxCmd.Parameters[1].Value = (r.ServDate) ?? DBNull.Value;
                            }


where reward is List<EndServReward> reward,why this happens ,and how to fix it ?

解决方案

?? is the null-coalescing operator.
It doesn't make sense to apply it to a value that cannot be null.

这篇关于运营商“??”不能应用于“System.DateTime”类型的操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆