c# – 无法将类型为’System.Byte []’的对象强制转换为’System.IConvertible’

前端之家收集整理的这篇文章主要介绍了c# – 无法将类型为’System.Byte []’的对象强制转换为’System.IConvertible’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. FMT fmt=new FMT();
  2.  
  3. public void ReadFmtHeader()
  4. {
  5. fmt.s_Sub_Chunk_ID_1 = reader.ReadBytes(4);
  6. fmt.ui_Sub_Chunk_Size_ID_1 = reader.ReadBytes(4);
  7. fmt.us_Audio_Format = reader.ReadBytes(2);
  8. fmt.us_Num_Channels = reader.ReadBytes(2);
  9. fmt.ui_Sample_Rate = reader.ReadBytes(4);
  10. fmt.ui_Byte_Rate = reader.ReadBytes(4);
  11. fmt.us_Block_Align = reader.ReadBytes(2);
  12. fmt.us_Bits_Per_Sample = reader.ReadBytes(2);
  13.  
  14. if (Convert.ToInt32(fmt.ui_Sub_Chunk_Size_ID_1) == 18)// Exception thrown on this line
  15. {
  16. // Read any extra values
  17. int fmtExtraSize = reader.ReadInt16();
  18. reader.ReadBytes(fmtExtraSize);
  19. }
  20. }

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

解决方法

你不能使用Convert.ToInt32将byte []转换为int;你需要 use a BitConverter.

猜你在找的C#相关文章