product?.price
当 product没有值的时候,不访问其 price属性;
当 product有值的时候再去访问其 price属性。
public int?num{
get;
set;
}
?代表int型的数值可以为null,表示可空类型,因为int类型初始值为0,加了?就可以赋值null了。
int i=null; 报错
int? i=null; 通过
interface PersonPartial {
name?: string;
age?: number;
}
将一个已知的类型每个属性都变为可选的。
属性为只读类型:
interface PersonReadonly {
readonly name: string;
readonly age: number;
}