DateTime?转化为DateTime,int? 转 int

深入理解C#---1.可空类型

https://blog.csdn.net/tianzeyu1992/article/details/52618131

 

原文:https://blog.csdn.net/qq_35309370/article/details/80096355

除了使用Convert.ToDatetime()外

还可以直接用 DateTime? .Value    获取到的就是一个DateTime类型的值

原文:https://www.cnblogs.com/valu/p/5916095.html

DateTime? dt2 = DateTime.Now;
dt2.GetValueOrDefault().ToString("yyyy-MM-dd");
**************************************************************
int? test = null;//定义一个int?赋值空
 int a = test ?? 0;//test??0  当test不为空时,直接返回值,为空时返回??后的值
 
int? n = null;
//int m1 = n;      // Will not compile.
int m2 = (int)n;   // Compiles, but will create an exception if x is null.
int m3 = n.Value;  // Compiles, but will create an exception if x is null.

int? a;
a.Value不就是int型
posted @ 2019-01-11 17:17  高山-景行  阅读(3283)  评论(0编辑  收藏  举报