【发布时间】:2015-02-15 20:39:05
【问题描述】:
有人可以在下面的代码中解释我吗?基本上它是什么,它在做什么,为什么我需要 mParentWindow?我不能只用 ParentWindow 来做吗
private BrowserWindow mParentWindow { get; set; }
public BrowserWindow ParentWindow {
get {
if (this.mParentWindow == null) {
this.mParentWindow = TopParentWindow();
}
return this.mParentWindow;
}
}
【问题讨论】:
-
什么需要解释......你是认真的你不理解你发布的代码......?这是一个开始学习的好地方C# Basics Tutorial - Properties
-
你了解Property 是什么吗?你认为这里发生了什么?很高兴您带着要解决的问题来到 c#,但最好在提出问题之前先阅读基本的 c# 教程。
-
延迟初始化 - 它确保无论您阅读
.ParentWindow多少次,检索它的进程 (TopParentWindow()) 只被调用一次,第一次需要它。 -
我只是困惑为什么我需要另一个属性“mParentWindow”来简单地获取 BrowserWindow。我想我应该这样做
codepublic BrowserWindow ParentWindow { get { if (this.ParentWindow == null) { this.ParentWindow = TopParentWindow(); } 返回 this.ParentWindow; } } -
mParentWindow 不是属性,而是字段。按照链接。
标签: c# coded-ui-tests