2016-11-28 70 views
0

我必須將我的c#轉換爲vb,但它沒有轉換100%,我堅持使用類對象將項添加到列表。如何添加一個項目與類在VB中的列表?

我在這裏得到錯誤(值類型 '布爾' 不能被轉換爲 '_Default.Courses')上的課程列表中添加:

Public Class Courses 
    Public courseName As String 
    Public qualName As String 
    Public providerName As String 
End Class 

...

While r.Read 
    Dim coursename As String = r("courseName").ToString 
    Dim qualname As String = r("qualName").ToString 
    Dim providername As String = r("providerName").ToString 
    courseList.Add(New Courses() With { 
     Key.courseName = coursename, 
     Key.qualName = qualname, 
     Key.providerName = providername 
    }) 
End While 

.. 。

這是原來的C#代碼:

while (r.Read()) 
{ 
    string coursename = r["courseName"].ToString(); 
    string qualname = r["qualName"].ToString(); 
    string providername = r["providerName"].ToString(); 

    courseList.Add(new Courses 
    { 
     courseName = coursename, 
     qualName = qualname, 
     providerName = providername 
    }); 
} 
+2

刪除'Key' – Slai

回答

0

更改您的代碼:

While r.Read 
    Dim coursename As String = r("courseName").ToString 
    Dim qualname As String = r("qualName").ToString 
    Dim providername As String = r("providerName").ToString 
    courseList.Add(New Courses() With { 
     .courseName = coursename, 
     .qualName = qualname, 
     .providerName = providername 
    }) 
End While 
相關問題