我正在Internet上查看是否有好的示例说明如何在初始化实例变量的同时初始化类中的共享成员。我确实找到了一个可能适合答案的表达式:
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但是您也有标准
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?
推荐答案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.
更多推荐
在VB.NET中的类中初始化共享成员的最佳方法是什么?
发布评论