假设我们有以下模型:
public class Father
{
public Child Child { get; set; }
public string Name { get; set; }
public Father() { }
}
public class Child
{
public Father Father;
public string Name { get; set; }
}
以及以下实现:
var father = new Father();
father.Name = "Brad";
var child = new Child();
child.Father = father;
child.Name = "Brian";
father.Child = child;
现在我的问题是:codesnippet #1 是否等同于 codesnippet #2?
还是运行代码片段#1 需要更长的时间?
代码片段#1:
var fatherName = father.Child.Father.Child.Father.Child.Name;
代码片段#2:
var fatherName = father.Name;