我被一個關於泛型類的問題困住了。我很困惑如何使用參數調用構造函數。泛型類VB.NET
我的界面:
Public Interface IDBObject
Sub [Get](ByRef DataRow As DataRow)
Property UIN() As Integer
End Interface
我的子類:
Public Class User
Implements IDBObject
Public Sub [Get](ByRef DataRow As System.Data.DataRow) Implements IDBObject.Get
End Sub
Public Property UIN() As Integer Implements IDBObject.UIN
Get
End Get
Set(ByVal value As Integer)
End Set
End Property
End Class
我的下一個類:
Public Class Users
Inherits DBLayer(Of User)
#Region " Standard Methods "
#End Region
End Class
我DBOBJECT類:
Public Class DBLayer(Of DBObject As {New, IDBObject})
Public Shared Function GetData() As List(Of DBObject)
Dim QueryString As String = "SELECT * ***;"
Dim Dataset As DataSet = New DataSet()
Dim DataList As List(Of DBObject) = New List(Of DBObject)
Try
Dataset = Query(QueryString)
For Each DataRow As DataRow In Dataset.Tables(0).Rows
**DataList.Add(New DBObject(DataRow))**
Next
Catch ex As Exception
DataList = Nothing
End Try
Return DataList
End Function
End Class
我在DBLayer對象的加星區域出現錯誤。
可能的原因是什麼?我能做些什麼來解決它?
我甚至想在IDBObject接口中添加New(byval someval as datatype)作爲重載構造。但它也給出了一個錯誤?我該怎麼做?
加入
的Sub New(BYVAL的DataRow如DataRow中)在IDBObject producess以下錯誤 '的Sub New' 不能在接口中聲明。
錯誤DBLayer對象 線製作人:DataList.Add(新澤西DBOBJECT(DataRow中)) 消息:參數不能被傳遞到上一個類型參數「新建」使用。
你會得到什麼錯誤? – 2010-06-01 12:01:09