VB.NET和sizeof

Kev*_*don 7 .net c# vb.net sizeof

我正在将一些代码从C#转换为VB.NET.我在C#中有以下行

var bytes = new byte[password.Length * sizeof(char)];
Run Code Online (Sandbox Code Playgroud)

MSDN上看来,VB.NET似乎没有sizeof运营商.我知道有一个Marshal.SizeOf但是进一步的MSDN文档声明返回的值可能与之不同sizeof.

有人可以帮忙吗?在VB.NET中是否有相同的声明?

附加信息

我的目标是将密码转换为字节数组,然后我可以散列,然后存储在数据库中或与之前存储的散列进行比较.但我不一定想得到与我的具体情况有关的答案.

Dim bytes(password.Length * xxx) As Byte
System.Buffer.BlockCopy(password.ToCharArray(), 0, bytes, 0, bytes.Length)
Dim sha512 = System.Security.Cryptography.SHA512.Create()
Dim hash = sha512.ComputeHash(bytes)

' compare hash or stroe in database
Run Code Online (Sandbox Code Playgroud)

Dav*_*jas 5

VB 中的“Len”运算符将执行此操作(但它适用于实例,因此您需要进行相应调整):

Dim bytes = New Byte((someString.Length * Len(New Char)) - 1){}
Run Code Online (Sandbox Code Playgroud)