Changing a VB assignment to c#?

  • Thread starter Thread starter Mark Relly
  • Start date Start date
M

Mark Relly

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 "binaryChallenge = 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.GetString(byteArray) ) 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
 
Mark Relly said:
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 "binaryChallenge = tmp" this assignment
(string = byte[]) is not valid in C#

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

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.
 
I think he means

byte[] tmp;
string binaryChallenge;

and

binaryChallenge = tmp;

causes an error

I suggest you do

binaryChallenge = System.Text.Encoding.ASCII.GetString(tmp, 0, tmp.Length);
 
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(byteArray);

however this still doesn't seem to work correctly

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

Mark Relly
 
In case of unicode use

binaryChallenge = System.Text.Encoding.Unicode.GetString(tmp, 0,
tmp.Length);

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

binaryChallenge = System.Text.Encoding.BigEndianUnicode.GetString(tmp,0,
tmp.Length);
 
Back
Top