我基于其他类创建了一个类。我试着在构造函数中为类赋值,但是会出错。
错误1'我'不能是作业的目标。
有没有办法解决它..?这是我创建的代码
Public Class tabelDSN
Inherits DataTable
Public Sub New(ByVal dt As DataTable)
Me = dt.Copy()
End Sub
Default Public ReadOnly Property rw(ByVal idx) As DataRow
Get
Return Me.Rows(idx)
End Get
End Property
End Class
答案 0 :(得分:1)
通过删除Inherits并添加私有DataTable字段来保存构造函数参数,可以使tabelDSN类成为DataTable类的包装器。代码如下所示:
Public Class tabelDSN
Private _dt as DataTable
Public Sub New(ByVal dt As DataTable)
_dt = dt.Copy()
End Sub
Default Public ReadOnly Property rw(ByVal idx) As DataRow
Get
Return _dt.Rows(idx)
End Get
End Property
End Class