无法隐式将'byte []'转换为'byte'

时间:2014-01-28 06:22:03

标签: c# .net

我的代码有一个类型转换错误

 int imglength = FileUpload2.PostedFile.ContentLength;
 byte imgarray=new byte[imglength];

5 个答案:

答案 0 :(得分:5)

您尝试将字节数组(byte[])分配给单个字节,因此出错。

请尝试以下代码:

byte[] imgarray = new byte[imglength];

答案 1 :(得分:4)

您不能将字节数组分配给字节

试试这个

byte[] bytearray = new byte[imglength];

答案 2 :(得分:1)

结构就像这样

byte[] Buffer = new byte[imglength];

答案 3 :(得分:1)

您可以使用以下代码:

int imageSize = fuImage.PostedFile.ContentLength;
System.IO.Stream imageStream = fuImage.PostedFile.InputStream;
byte[] imageContent = new byte[imageSize];
int status = imageStream.Read(imageContent, 0, imageSize);

此代码将postedfile转换为字节流

答案 4 :(得分:0)

检查一下:

int imgLength = FileUpload2.PostedFile.ContentLength;
byte[] revLength= BitConverter.GetBytes(imgLength);
Array.Reverse(revLength);
byte[] imgLengthB = revLength;
相关问题