• 可空类型的处理 itprobie


    在程序中经常碰到时间,或是数字类型信息,这些字段在数据库中可以为空,但是时间和数字等值类型都必须要求有值。

    可空类型顾名思义类型可以为空,它使得值类型可以为空,定义型如className?,例如时间的可空类型为DateTime?。

    将String类型转换成DateTime?

     1     private DateTime? GetNullableDateTime(string str)
     2     {
     3         return string.IsNullOrEmpty(str) ? null :
     4             (DateTime?)Convert.ToDateTime(str);
     5     }
     6 
     7     private string CoverToString(DateTime? dt)
     8     {
     9         return Convert.ToString(dt);
    10     }
    11 
    12     private System.Data.Common.DbParameter GetDbParameter(string parameterName,DateTime? dt)
    13     {
    14         return new System.Data.SqlClient.SqlParameter(parameterName, dt);
    15     }
  • 相关阅读:
    VSCode配置Python开发环境
    图像特征——边缘
    关于相机内参中的焦距fx和fy
    摄影变换和仿射变换
    为什么要引入齐次坐标
    链表一
    从小问题看懂链表
    类与对象
    排序一
    数组
  • 原文地址:https://www.cnblogs.com/guohu/p/2700944.html
Copyright © 2020-2023  润新知