帮助将C#代码转换为Vb 8.0

时间:2009-02-11 19:30:38

标签: c# vb.net

 private void Form1_Load(object sender, EventArgs e)
    {

               List<CaclulatedData> tests = new List<CaclulatedData>
                                   {
                                    new CaclulatedData()
                                     {
                                      Bonds = "First Bond",
                                      TransactionList = new List<TransactionData>
                                                {
                                                 new TransactionData() {Debit = "DebitData"}
                                                }
                                     },
                                    new CaclulatedData()
                                     {
                                      Bonds = "Second Bond",
                                      TransactionList = new List<TransactionData>
                                                {
                                                 new TransactionData() {Debit = "123123"},
                                                 new TransactionData() {Debit = "12312", Credit = "3453"}
                                                }
                                     }
                                   };
               gridControl1.DataSource = tests;

    }

}
public class JEString
{

    public string Bonds { get; set; }

}

public class CaclulatedData : JEString
{
    public List<TransactionData> TransactionList { get; set; }
}


public class TransactionData
{
    public string Debit { get; set; }
    public string Credit { get; set; }
}

3 个答案:

答案 0 :(得分:3)

您也可以使用反射器将您的.net程序集转换为以下任何语言。

  • IL
  • C#
  • VB.NET
  • 的Delphi
  • MC ++

答案 1 :(得分:2)

答案 2 :(得分:1)

您的部分问题是vb8尚不支持您的C#代码正在使用的某些功能(例如,自动属性和集合初始值设定项),因此翻译不是1:1。其中一些功能是在VB9中添加的。那就是说,并不难:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim tests As New List(Of CaclulatedData)(2)

    tests.Add(New CalculatedData())
    tests(0).Bonds = "First Bond"
    tests(0).TransactionList.Add(New TransactionData())
    tests(0).TransactionList(0).Debit = "DebitData"

    tests.Add(New CalculatedData())
    tests(1).Bonds = "Second Bond"
    tests(1).TransactionList.Add(New TransactionData())
    tests(1).TransactionList(0).Debit = "123123"
    tests(1).TransactionList.Add(New TransactionData())
    tests(1).TransactionList(1).Debit = "12312"
    tests(1).TransactionList(1).Credit = "3453"

    gridControl1.DataSource = tests
End Sub

Public Class JEString
    Private _Bonds As String
    Public Property Bonds() As String
       Get
          Return _Bonds
       End Get
       Set(ByVal value As String)
           _Bonds = value
       End Set
    End Property
End Class

Public Class CaclulatedData 
    Inherits JEString

    Private _TransactionList As New List(Of TransactionData)()
    Public ReadOnly Property TransactionList() As List(Of TransactionData)
        Get
            Return _TransactionList
        End Get
    End Property
End Class


Public Class TransactionData
    Private _Debit As String
    Private _Credit As String

    Public Property Debit() As String
       Get
          Return _ Debit
       End Get
       Set(ByVal value As String)
           _ Debit = value
       End Set
    End Property

    Public Property Credit() As String
       Get
          Return _ Credit
       End Get
       Set(ByVal value As String)
           _Credit = value
       End Set
    End Property
End Class