【发布时间】:2012-04-07 00:20:46
【问题描述】:
我有一个类,它具有以下由构造函数中的方法生成的属性。
Public Class clsLoadTables
Private _ds As New DataSet
Public Property ds() As DataSet
Get
Return _ds
End Get
Set(ByVal value As DataSet)
_ds = value
End Set
End Property
Sub New()
Try
loadCSVTableII()
loadXMLFiles(pathMainTable, "MainRMDTable")
loadXMLFiles(pathBeneLifeExp, "pathBeneLifeExp")
Catch ex As Exception
MessageBox.Show(ex.Message)
Throw
End Try
End Sub
End Class
我的问题是我不想继承这个类,但是我还有其他类需要访问 ds DataSet 属性。如果可能的话,我不想使用继承,也不想在程序中多次加载我的数据表。
这是我尝试访问未继承 clsLoadTables 的另一个类中的属性失败:
Dim tableRow As DataRow = ds.Tables("MainRMDTable").Select(String.Format("age={0}", age.ToString()))(0)
关于如何在不使用类继承或全局模块的情况下访问我只想在程序中从多个类加载一次的数据集的任何想法?
【问题讨论】:
-
该类的目的是什么,它与全局模块(您不想使用)有何不同?
-
您可以将其设为
shared并将其加载到shared constructor。 -
Pavel - 你说的不对。我试图这样做是为了强迫自己成为一个更加面向对象的程序员
-
蒂姆 - 我现在正在调查。感谢您的评论。
标签: .net vb.net oop class inheritance