有人可以解释 --> private BrowserWindow mParentWindow { get;放; }

Can someone explain --> private BrowserWindow mParentWindow { get; set; }

有人可以在下面的代码中解释一下吗?基本上它是什么,它在做什么,为什么我需要 mParentWindow?我不能只用 ParentWindow

private BrowserWindow mParentWindow { get; set; }
public BrowserWindow ParentWindow { 
   get {
      if (this.mParentWindow == null) {
        this.mParentWindow = TopParentWindow();
      }
      return this.mParentWindow;
   }
}

基本上,您可以将 mParentWindow 设置为 public 并删除 m。您提供的这段代码会在 [=33] 中创建一个只读的 属性 =].您已经添加了一个 private BrowserWindow,您可以在它所属的 class 中随意更改它,但不能在其外部访问或更改。然后你有只读的 属性 可以访问但不能从其父 class 外部更改。 我将在下面尝试更好地解释这一点:

private BrowserWindow mParentWindow { get; set; }

这一行创建了一个 BrowserWindow class 的实例,由于 get 函数的存在,但只能在父 class 内部访问和更改该实例因为它是 private.

public BrowserWindow ParentWindow
{ 
    get
    {
        if (this.mParentWindow == null)
        {
            this.mParentWindow = TopParentWindow();
        }
        return this.mParentWindow;
    } 
}

这段代码创建了一个 BrowserWindow class 的实例,可以访问但不能更改,因为有 get 函数但没有 set 函数。这可以在 class 之外访问,因为它是 public。 在 get 函数中,代码表示如果之前未设置 mParentWindow 的值,则将其设置为 TopParentWindow 函数的结果。 在此之后它 returns 的值 mParentWindow.