System.DateTime的?到system.datetime [英] System.datetime? To system.datetime

查看:322
本文介绍了System.DateTime的?到system.datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一条说System.datetime的错误?无法转换为System.datetime,但存在显式转换。我做了谷歌搜索并找到了一个建议的解决方案......但我仍然得到错误。 OPT_EXP是一个可以为空的列。请看一看并告诉我出了什么问题?



我尝试了什么:



I'm getting an error saying System.datetime? can't be converted to System.datetime, but an explicit conversion exists. I did a Google search and found a proposed solution... but I still get the error. OPT_EXP is a nullable column. Please take a look and show me what's wrong?

What I have tried:

       public class MC_VARIABLES
       {
           public DateTime? OPT_EXP;
           public DateTime? mOPT_EXP
           {
               get { return mOPT_EXP; }
               set { mOPT_EXP = value; }
           }
       }

public void DTE()
   {
       decimal DTE;

       foreach (KeyValuePair<int,> KVP in dctMC)
       {
           if (KVP.Value.OPT_EXP.HasValue)
           {
               DateTime TDY = DateTime.Now;
               DateTime EXP = KVP.Value.OPT_EXP;           //cannot implicitly convert system.datetime? to system.datetime....not sure how to fix this
               TimeSpan DaysToExp = TDY - EXP;
               DTE = (decimal)(DaysToExp.TotalDays) / 365;
           }
       }
   }

推荐答案

使用:

Use:
DateTime EXP = KVP.Value.OPT_EXP.Value;


这篇关于System.DateTime的?到system.datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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