vb.net “一维字节数组”类型的值无法转换为字节

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27569980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:35:26  来源:igfitidea点击:

Value of type '1-dimensional array of byte' cannot be converted to a byte

.netvb.net

提问by user3516240

I'm trying to pass values to a backgroundworker. I previously posted to ask how it could be done here. An answer directed me to this code, but I'm having issues trying to use it. Here's what I'm doing:

我正在尝试将值传递给后台工作人员。我之前发帖询问如何在这里完成。一个答案将我定向到此代码,但我在尝试使用它时遇到了问题。这是我在做什么:

Class MyParameters
    Friend strInputFile As String
    Friend strOutputFile As String
    Friend bytKey As Byte
    Friend bytIV As Byte
    Friend Direction As New CryptoAction
End Class

.

.

Private Sub bnEcrypt_Click(sender As Object, e As EventArgs) Handles bnEcrypt.Click
        Dim bytKey As Byte()
        Dim bytIV As Byte()


        'Send the password to the CreateKey function.
        bytKey = CreateKey(txtPass.Text)
        'Send the password to the CreateIV function.
        bytIV = CreateIV(txtPass.Text)

        Dim m As New MyParameters
        m.strInputFile = txtFile.Text
        m.strOutputFile = txtPlaceIn.Text
        m.bytKey = bytKey
        m.bytIV = bytIV
        m.Direction = CryptoAction.ActionDecrypt

But I'm getting a error: Value of type '1-dimensional array of byte' cannot be converted to a byte'. on these two:

但是我收到一个错误:类型 '1-dimensional array of byte' 的值不能转换为一个字节'。关于这两个:

        m.bytKey = bytKey
        m.bytIV = bytIV

Any help?

有什么帮助吗?

采纳答案by Patrick Hofman

You have your variables defined as a Byteinstead of a byte array Byte().

您将变量定义为 aByte而不是字节数组Byte()

Use this:

用这个:

Friend bytKey As Byte()
Friend bytIV As Byte()

回答by Jason Faulkner

Your class needs to accept a Byte()instead:

你的班级需要接受一个Byte()

Class MyParameters
    Friend strInputFile As String
    Friend strOutputFile As String
    Friend bytKey As Byte() ' <-- Changed from Byte
    Friend bytIV As Byte() ' <-- Changed from Byte
    Friend Direction As New CryptoAction
End Class

回答by Guffa

You have declared two byte fields in the class. Declare two arrays instead:

您已经在类中声明了两个字节字段。改为声明两个数组:

Friend bytKey() As Byte
Friend bytIV() As Byte