473,503 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "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
Nov 15 '05 #1
4 1178
Mark Relly <ma**@mslnet.co.uk> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
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);

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #3
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
Nov 15 '05 #4
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(tm p,0,
tmp.Length);

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
10198
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
7
6566
by: Frostillicus | last post by:
Hi, I've written some javascript to randomly choose a classical music composer's picture and sample audio and display it on my home page (http://marc.fearby.com/), and this works fine in Mozilla...
4
2752
by: David Coffin | last post by:
I'd like to subclass int to support list access, treating the integer as if it were a list of bits. Assigning bits to particular indices involves changing the value of the integer itself, but...
6
2268
by: reynard | last post by:
I have a page that uses this doctype <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> but when I change to this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
2
2007
by: Gary Dale | last post by:
I have a form with a pull-down list with six options, each of which has a value set. The value is the e-mail account name (without the domain) of a group while the displayed value is the full name...
1
4794
by: 32Alpha | last post by:
Hi, first post here. First off, this IS a homework assignment for an operating systems class, but the question isn't "how do i do the assignment" but "why is my particular implementation not...
3
1497
by: flyfree | last post by:
>>def fooA(y): y = return y y = 3 y = 4 return y
6
6251
by: Adam C. | last post by:
We have a situation where we want a Swig-generated Python class to have a different base (not object). It doesn't appear that we can coerce Swig into generating the class we want at present (but we...
4
2471
by: yawnmoth | last post by:
I'm trying to write a script whereby the body background is changed to back (from white) when the mouse button is held down and kept held down. When you lift it up, I'd like it to change back to...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.