zoukankan      html  css  js  c++  java
  • C# Datetime 赋空

    如果我们想把一个实例是Datetime的属性,设定为空。

    ① 把这个Datetime的属性的数据类型设定为 Nullable<DateTime> ,

        简写格式是DateTime?  最好用Nullable<DateTime>这种形式。

    ② 使用的时候先判断一下是否有值是否为null,若没有值或者为null,

    我们可以吧值设定为null.

    以下是一个实例:

        public class ReturnInfoModel
        {

          private Nullable<DateTime> _ope_date;

            /// <summary>
            /// 操作日期
            /// </summary>
            public Nullable<DateTime> ope_date
            {
                set { _ope_date = value; }
                get { return (Nullable<DateTime>)_ope_date; }
            }

        }

    使用                        //退换货日期
                            string strReceiveTime = returnInfo.ReceiveTime;
                            if (String.IsNullOrEmpty(strReceiveTime))
                            {
                                returnInfoModel.chaorret_date = null;
                            }
                            else
                            {
                                returnInfoModel.chaorret_date = DateTime.Parse(strReceiveTime);
                            }

  • 相关阅读:
    Docker安装及简单使用
    常用编程语言注释符
    常用正则标记
    Android studio 使用startService报错:IllegalStateException
    Mybatis映射文件中#取值时指定参数相关规则
    IDEA Maven项目的Mybatis逆向工程
    循环结构
    每日思考(2020/03/05)
    分支结构
    每日思考(2020/03/04)
  • 原文地址:https://www.cnblogs.com/YangBinChina/p/2703641.html
Copyright © 2011-2022 走看看