在VB.NET中的类中初始化共享成员的最佳方法是什么? [英] What's the best way to initialize shared members in a class in VB.NET?

查看:90
本文介绍了在VB.NET中的类中初始化共享成员的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在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中的类中初始化共享成员的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆