Jump to content

Converter de vb.net para c#


n1ckooo
 Share

Recommended Posts

Class UnpackAllMarkets       'For getAllMArkets
  Public marketData As MarketDataType() = {}  'The returned array of market data
  Private Const BaseDate As DateTime = #1/1/1970#
  Private Const ColonCode = "&%^@"  'The substitute code for "\:"

  Sub New(ByVal MarketString As String)
    Dim n As Integer, Mdata, Field As String()

    Mdata = MarketString.Replace("\:", ColonCode).Split(":") 'Get array of Market substrings
    n = UBound(Mdata) - 1
    ReDim marketData(n)

    For i = 0 To n
      Field = Mdata(i + 1).Replace("\~", "-").Split("~") 'Get array of data fields
      marketData(i) = New MarketDataType
      With marketData(i)
        .marketId = Field(0)   'Load the array items
        .marketName = Field(1).Replace(ColonCode, ":")
        .marketType = Field(2)
        .marketStatus = Field(3)
        .eventDate = BaseDate.AddMilliseconds(Field(4))
        .menuPath = Field(5).Replace(ColonCode, ":")
        .eventHeirachy = Field(6)
        .betDelay = Field(7)
        .exchangeId = Field(8)
        .countryCode = Field(9)
        .lastRefresh = BaseDate.AddMilliseconds(Field(10))
        .noOfRunners = Field(11)
        .noOfWinners = Field(12)
        .totalAmountMatched = Val(Field(13))
        .bspMarket = (Field(14) = "Y")
        .turningInPlay = (Field(15) = "Y")

      End With
    Next
  End Sub
End Class

Class MarketDataType           'For getAllMarkets data
  Public marketId As Integer
  Public marketName As String
  Public marketType As String
  Public marketStatus As String
  Public eventDate As DateTime
  Public menuPath As String
  Public eventHeirachy As String
  Public betDelay As Integer
  Public exchangeId As Integer
  Public countryCode As String
  Public lastRefresh As DateTime
  Public noOfRunners As Integer
  Public noOfWinners As Integer
  Public totalAmountMatched As Double
  Public bspMarket As Boolean
  Public turningInPlay As Boolean
End Class


Private Sub bMarkets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bMarkets.Click
  Print("*** Markets ***")
  Dim oMarketsReq As New BFUK.GetAllMarketsReq
  Dim oMarketsResp As BFUK.GetAllMarketsResp
  With oMarketsReq
    .header = oHeaderUK()
    ReDim .eventTypeIds(0) : .eventTypeIds(0) = 7  'For horse racing
    ReDim .countries(1) : .countries(0) = "GBR" : .countries(1) = "ZAF"
    .fromDate = Today
    .toDate = Today.AddDays(1)
  End With
  oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)  'Call the UK API
  With oMarketsResp
    CheckHeader(.header)
    Print("ErrorCode = " & .errorCode.ToString)
    If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
       Dim AllMarkets As New UnpackAllMarkets(.marketData)  
With AllMarkets
  For i = 0 To .marketData.Length - 1
    With .marketData(i)
      Print(.marketID & " " & .marketStatus & "  " & .marketName & “  “ & .menuPath)
    End With
  Next
End With
    End If
  End With
End Sub

Alguém me ajuda a converter isto para C#?

Link to comment
Share on other sites

Se é esse o caso, porque raio não meteste só as partes onde aparecia ReDim ?

Nem C# nem VB conseguem fazer isso. O ReDim é um atalho do VB que internamente cria uma nova array com o novo tamanho e copia os dados da original.

Basta escrever um algoritmo em C# para tal.

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Link to comment
Share on other sites

Se é esse o caso, porque raio não meteste só as partes onde aparecia ReDim ?

Nem C# nem VB conseguem fazer isso. O ReDim é um atalho do VB que internamente cria uma nova array com o novo tamanho e copia os dados da original.

Basta escrever um algoritmo em C# para tal.

Voces falam com uma arrogancia um pouco estranha,para uma comunidade...  mas era mesmo isso que queria saber... obrigado...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.