无法将类型为'System.Byte []'的对象强制转换为'System.IConvertible'

Ale*_*vid 6 c#

FMT fmt=new FMT();    

public void ReadFmtHeader()
{
    fmt.s_Sub_Chunk_ID_1 = reader.ReadBytes(4);
    fmt.ui_Sub_Chunk_Size_ID_1 = reader.ReadBytes(4);
    fmt.us_Audio_Format = reader.ReadBytes(2);
    fmt.us_Num_Channels = reader.ReadBytes(2);
    fmt.ui_Sample_Rate = reader.ReadBytes(4);
    fmt.ui_Byte_Rate = reader.ReadBytes(4);
    fmt.us_Block_Align = reader.ReadBytes(2);
    fmt.us_Bits_Per_Sample = reader.ReadBytes(2);

    if (Convert.ToInt32(fmt.ui_Sub_Chunk_Size_ID_1) == 18)// Exception thrown on this line
    {
        // Read any extra values
        int fmtExtraSize = reader.ReadInt16();
        reader.ReadBytes(fmtExtraSize);
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试读取波形文件,然后使用标题信息重新创建它并保存到文件.我不知道是什么问题.任何人都可以帮我吗?

Ada*_*ras 9

您无法将a转换byte[]int使用Convert.ToInt32; 你需要使用一个BitConverter.

  • 不同之处在于,"BitConverter"的构建完全符合您的要求:获取一个字节数组并将它们转换为整数表示形式.`Convert.Int32`用于转换已经是整数的任何东西,或者可以使用`IConvertible`接口转换为整数. (2认同)