Changing a VB assignment to c#?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Relly

    #1

    Changing a VB assignment to c#?

    Hello,

    I would be very grateful if anyone could help me.
    I am working with vb legacy code and have little vb knowledge.

    I am attempting to transform this code into C# but I have a problem

    In the VB code:

    Dim tmp() As Byte
    Dim binaryChallenge As String

    binaryChallenge = tmp

    I have a problem with the line "binaryChalleng e = tmp" this assignment
    (string = byte[]) is not valid in C#

    I was wondering if anyone knew how to write this line in c# code.

    I have tried various things (E.g. challenge =
    asciiEncoding.G etString(byteAr ray) ) with no success as the values do not
    match in each version (c# and vb).

    Anybody who could help me it would be appreciated.

    Thanks

    Mark Relly


  • Jon Skeet [C# MVP]

    #2
    Re: Changing a VB assignment to c#?

    Mark Relly <mark@mslnet.co .uk> wrote:[color=blue]
    > I would be very grateful if anyone could help me.
    > I am working with vb legacy code and have little vb knowledge.
    >
    > I am attempting to transform this code into C# but I have a problem
    >
    > In the VB code:
    >
    > Dim tmp() As Byte
    > Dim binaryChallenge As String
    >
    > binaryChallenge = tmp
    >
    > I have a problem with the line "binaryChalleng e = tmp" this assignment
    > (string = byte[]) is not valid in C#
    >
    > I was wondering if anyone knew how to write this line in c# code.[/color]

    Well, what do you actually want to do? What do you want the result to
    be, *exactly*? (I don't know what the VB does.) If you could give an
    example input and output, that would help a lot.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Morten Wennevik

      #3
      Re: Changing a VB assignment to c#?

      I think he means

      byte[] tmp;
      string binaryChallenge ;

      and

      binaryChallenge = tmp;

      causes an error

      I suggest you do

      binaryChallenge = System.Text.Enc oding.ASCII.Get String(tmp, 0, tmp.Length);

      --
      Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

      Comment

      • Mark Relly

        #4
        Re: Changing a VB assignment to c#?

        Morten is correct to a certain degree.

        binaryChallenge = tmp;

        causes an error in c# but works fine in vb.

        What I am trying to do is replicate the assignment of a byte() to a string
        in vb in c#

        When in print the byte() contents in vb i get the string
        ??????????????? ??????????????? ?? as it is unicide encoded.

        My best attmept to duplicate this in c# is

        challenge = unicodeEncoding .GetString(byte Array);

        however this still doesn't seem to work correctly

        I apologise if I am explaining this badly and thanks for your help

        Mark Relly


        Comment

        • Morten Wennevik

          #5
          Re: Changing a VB assignment to c#?

          In case of unicode use

          binaryChallenge = System.Text.Enc oding.Unicode.G etString(tmp, 0,
          tmp.Length);

          or in case of big endian unicode arrangement in the byte array use

          binaryChallenge = System.Text.Enc oding.BigEndian Unicode.GetStri ng(tmp,0,
          tmp.Length);

          --
          Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

          Comment

          Working...