2014-02-26 64 views
0
Byte[] byteSource = System.IO.File.ReadAllBytes(FileInputPath); 
int fileOffset = BitConverter.ToInt32(byteSource); 

我想转换字节数组为int但其显示的错误转换字节[]为int在C#

+3

如果你读完整个错误,它会告诉你到底发生了什么错误。 – CodeCaster

回答

1

“否Toint32重载方法”没有的ToInt32超负荷采取单一的参数。 The method需要数组和开始索引。

int fileOffset = BitConverter.ToInt32(byteSource, 0); 
+0

谢谢@Andrei其作品 –

+0

但转换后有一个问题'fileOffset'和'byteSource'的大小是不同的。为什么? –

+0

@RaaJivYadav,有什么不同? – Andrei

1

是的,没有方法过载的单个参数。您还需要指定偏移值。

int fileOffset = BitConverter.ToInt32(byteSource, 0);