1、三目运算符(?:)
这个用的多就不用多说了。
2、可空运算(?)
单?,放在类名,数据类型后面,表是这个变量可以是null;
例:
int a1=null; //会报错“无法将 null 转换为 int” int? a2=null; //不会报错
Vector3? v = null; //可空
3、null合并运算符(??)
string? s1; //定义可空字符串变量s1 s1=s1 ?? ""; //如果s1==null,就将s1赋值为""
1、三目运算符(?:)
这个用的多就不用多说了。
2、可空运算(?)
单?,放在类名,数据类型后面,表是这个变量可以是null;
例:
int a1=null; //会报错“无法将 null 转换为 int” int? a2=null; //不会报错
Vector3? v = null; //可空
3、null合并运算符(??)
string? s1; //定义可空字符串变量s1 s1=s1 ?? ""; //如果s1==null,就将s1赋值为""