如何在VB.NET中执行此操作?

时间:2011-11-08 07:37:01

标签: c# vb.net domaincontext

我将此C#代码转换为VB.net时遇到问题。 loadLecturer在转换为VB.NET后似乎有问题

VB代码就在afterInitializeComponent()

之后
context.Load(context.GetLecturesQuery(), LoadLecturer, Nothing)

我希望转换和调试的C#代码

private void LoadLecturer(LoadOperation<tblLecturer> obj)
{
    foreach (var item in obj.Entities)
    {
        cbLID.Items.Add(item.lecturerID + " - " + item.lfirstName + " " + item.llastName);
    }
}

3 个答案:

答案 0 :(得分:3)

鉴于评论,听起来这不是导致你悲伤的方法本身,而是你如何调用 - 因为在原始代码中你正在使用方法组转换。我怀疑它很简单:

context.Load(context.GetLecturesQuery(), AddressOf LoadLecturer, Nothing)

答案 1 :(得分:1)

点击此链接for the VB.NET converter这就是我得到的内容:)

Private Sub LoadLecturer(obj As LoadOperation(Of tblLecturer))
For Each item As var In obj.Entities
    cbLID.Items.Add(Convert.ToString(item.lecturerID) & " - " & Convert.ToString(item.lfirstName) & " " & Convert.ToString(item.llastName))
Next
End Sub

答案 2 :(得分:0)

Private Sub LoadLecturer(obj As LoadOperation(Of tblLecturer))
    For Each item As var In obj.Entities
        cbLID.Items.Add(Convert.ToString(item.lecturerID) & " - " & Convert.ToString(item.lfirstName) & " " & Convert.ToString(item.llastName))
    Next
End Sub