VB.net计算在命名空间中创建的类的数量
我正在尝试学习一点关于使用名称空间的知识,目前我使用名称空间创建了两个项。但在将来,当正确实现时,将有x个使用名称空间创建的项 我如何计算存在的“cilinder”的数量VB.net计算在命名空间中创建的类的数量,vb.net,class,namespaces,Vb.net,Class,Namespaces,我正在尝试学习一点关于使用名称空间的知识,目前我使用名称空间创建了两个项。但在将来,当正确实现时,将有x个使用名称空间创建的项 我如何计算存在的“cilinder”的数量 Public Class Form1 ' Test for using namespace Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click ' Create cilinder
Public Class Form1
' Test for using namespace
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
' Create cilinder 1
Dim Cilinder_1 As New BODY_NAMESPACE.Body_Cilinder
Cilinder_1.Index = 1
Debug.Print(Cilinder_1.Index)
' Create cilinder 2
Dim Cilinder_2 As New BODY_NAMESPACE.Body_Cilinder
Cilinder_2.Index = 2
Debug.Print(Cilinder_2.Index)
End Sub
End Class
Namespace BODY_NAMESPACE
Class Body_Cilinder
Private _Index As Integer
Public Property Index() As Integer
Get
Index = _Index
End Get
Set(ByVal value As Integer)
_Index = value
End Set
End Property
End Class
End Namespace
经过进一步的挖掘,我们找到了解决办法。我使用了一个糟糕的搜索词
Public Class Form1
' Test for using namespace
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
' Create cilinder 1
Dim Cilinder_1 As New BODY_NAMESPACE.Body_Cilinder
Cilinder_1.Index = 1
Debug.Print(Cilinder_1.Index)
' Create cilinder 2
Dim Cilinder_2 As New BODY_NAMESPACE.Body_Cilinder
Cilinder_2.Index = 2
Debug.Print(Cilinder_2.Index)
' Count the cilinders
Debug.Print(BODY_NAMESPACE.Body_Cilinder.Count)
End Sub
End Class
Namespace BODY_NAMESPACE
' Class that defines all the Cilinders properties for easy access.
Class Body_Cilinder
' Counter to determinate the cilinder quantity required.
Public Shared Count As Integer = 0
Private _Index As Integer
Private _Height As Double
' Cilinder Index number As Integer for finding the position.
Public Property Index() As Integer
Get
Index = _Index
End Get
Set(ByVal value As Integer)
_Index = value
End Set
End Property
' Cilinder Height to define the cilinder height.
Public Property Height() As Double
Get
Height = _Height
End Get
Set(value As Double)
_Height = value
End Set
End Property
' Add Cilinder count every-time a new "Body Cilinder" instance Is created
Public Sub New()
Count = Count + 1
End Sub
End Class
End Namespace
名称空间更像是类的组织方式
System.Drawing
包含与绘图相关的内容,而System.Data
存储各种数据库提供程序。它与对象(而不是类)的创建位置没有太大关系Body\u Cilinder
驻留在Body\u命名空间中这一事实并不意味着对象就是在那里创建的(根据您的标题)。名称空间组织代码而不是对象Imports BODY_名称空间
将排除将其作为类型名的一部分