我在 C# 中有如下代码:
If (this._university != Null and this._university.department !=null &&
this._university.department.class !=null &&
this._university.department.class.student != null &&
this._university.department.class.student.name != null &&
this._university.department.class.student.name.firstname != null &&
this._university.department.class.student.name.firstname !=String.empty)
{
// selecting first letter of Firstname
var F_firstname = this._university.department.class.student.name.firstname[0].tostring();
}
但是代码对于检查空对象看起来很糟糕。我们有更好的方法来检查对象的空值吗?
千巷猫影
相关分类