c# 可空值类型和string

2019-07-24  本文已影响0人  柒轩轩轩轩

可空值类型

Nullable<bool>

Nullable<int> indexOfM = null;
Nullable<bool> b = 

string

string name = "nick"
string name = null;
string name = "";
string name = " "

判断null和空,空白string

image.png
int? num = 2;
System.Console.WriteLine(num.HasValue);//true
System.Console.WriteLine(num.Value);//2

Nullable<T>转换

int i = 3;
int? j = i;

int? a = 3;
int b = (int)a;
上一篇下一篇

猜你喜欢

热点阅读