在 VB.NET 中初始化类中的共享成员的最佳方法是什么?
我在互联网上查找是否有任何关于如何在初始化类中的共享成员的同时初始化实例变量的好示例。我确实找到了一个可能适合答案的表达式:
Shared Sub New()
'Declare shared members
End Sub
但是您也有标准的
Sub New()
'Declare instance members
End Sub
How do I初始化实例和共享成员,而无需在每次从类创建对象时重新初始化共享成员?
I was looking on the Internet to see if there were any good examples on how to initialize shared members within a class while still initializing instance variables. I did find an expression that might fit to the answer:
Shared Sub New()
'Declare shared members
End Sub
But you also have the standard
Sub New()
'Declare instance members
End Sub
How do I initialize both instance and shared members without re-initializing the shared members every time an object is created from a class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Shared Sub New
(也称为类型构造函数)对于每种类型(即在 AppDomain 内)仅执行一次,因此其中的任何成员初始化都不会被执行。对每个实例重复。Shared Sub New
(also known as a type constructor) is executed only once for each type (within an AppDomain, that is), so any member initialization in there will not be be repeated for each instance.