title: Generic Class VB.NET
body: <p>I am stuck with a problem about generic classes. I am confused how I call the constructor with parameters.</p>
  
  <p>My interface:</p>
  
  <pre><code>Public Interface IDBObject
      Sub [Get](ByRef DataRow As DataRow)
      Property UIN() As Integer
  End Interface
  </code></pre>
  
  <p>My Child Class:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>My Next Class:</p>
  
  <pre><code>Public Class Users
      Inherits DBLayer(Of User)
  
  #Region " Standard Methods "
  
  #End Region
  End Class
  </code></pre>
  
  <p>My DBObject Class:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I get error in the starred area of the DBLayer Object.</p>
  
  <p>What might be the possible reason? what can I do to fix it?</p>
  
  <p>I even want to add New(byval someval as datatype) in IDBObject interface for overloading construction. but it also gives an error? how can i do it?</p>
  
  <p>Adding </p>
  
  <p>Sub New(ByVal DataRow As DataRow) in IDBObject producess following error
  'Sub New' cannot be declared in an interface.   </p>
  
  <p>Error Produced in DBLayer Object 
  line: DataList.Add(New DBObject(DataRow))
  Msg: Arguments cannot be passed to a 'New' used on a type parameter.    </p>