在 Windows 窗体项目中,为什么设计器在 VB.NET 中默认使用 FriendWithEvents
属性,而在 C# 中默认使用 private
属性?
例如,在 form.designer.
文件中:
.cs
private Label Label1;
.vb
Friend WithEvents Label1 as Label;
对于 WithEvents
,它或多或少是清楚的(显然是为了使用 Handles
)。但为什么在 Visual Basic 中是Friend 而在 C# 中是 private?
最佳答案
Friend
用于与较旧的 Visual Basic 代码兼容,其中通常在包含它的窗体之外使用控件。
在 C# 中没有这种必要性。
private
是新代码的更好解决方案。
关于c# - Visual Basic 中的“Friend WithEvents”与 C# 中的 'private',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1922323/