在VB.NET中的类中初始化共享成员的最佳方法是什么?

编程入门 行业动态 更新时间:2024-10-28 02:24:18
本文介绍了在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中的类中初始化共享成员的最佳方法是什么?

本文发布于:2023-11-08 11:50:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569293.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:初始化   类中   成员   方法   VB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!