Monday, 15 June 2015

cannot convert from byte to string (VB.Net to C#) -



cannot convert from byte to string (VB.Net to C#) -

i have code written in vb.net , translated c# (through site). code not complicated of translation turned out fine no problems ever. 1 problem, though, causing me headache , while referenced in many websites (including one), still can't run. have function in vb.net decalred as:

public shared function utf8hextobyte(byval str string) byte

and translator altered to:

public static byte utf8hextobyte(string str)

later on, in c# code, i'm calling function:

(int = 0; <= key1.length - 1; i++) { key1[i] = 16 * utf8hextobyte(tempkey1[2 * i]) + utf8hextobyte(tempkey1[2 * + 1]); }

but working in vb.net not work here. i'm getting error:

error 7 best overloaded method match 'maker.resources.makec.utf8hextobyte(string)' has invalid arguments

error 8 argument 1: cannot convert 'byte' 'string'

now, guess problem utf8hextobyte receiving string , returning byte, whereas give byte tempkey1 , not string. work @ vb.net code, i'm confused... here's code vb.net:

for integer = 0 key1.length - 1 key1(i) = 16 * utf8hextobyte(tempkey1(2 * i)) + utf8hextobyte(tempkey1(2 * + 1)) next

tempkey byte[], key1 byte[].

any help do. i'm stuck on one.

i'm not great vb.net, quick bit of test code shows it's quite happy me passing byte function expects string. not c# going happy @ all, you've got no selection write code conversion.

to , maintain semantics of original code, need figure out vb.net convert byte string , duplicate it.

it not @ improbable phone call byte's tostring() method, so

key1[i] = 16 * utf8hextobyte(tempkey1[2 * i].tostring()) + utf8hextobyte(tempkey1[2 * + 1].tostring());

one thing find in c# it's lot stricter types , type conversions, forcing think how info changes 1 format another.

c# vb.net

No comments:

Post a Comment