C# 无法隐式转换';字节[]和#x27;至';字节';
我的给定代码存在类型转换错误C# 无法隐式转换';字节[]和#x27;至';字节';,c#,.net,C#,.net,我的给定代码存在类型转换错误 int imglength = FileUpload2.PostedFile.ContentLength; byte imgarray=new byte[imglength]; 您试图将字节数组(byte[])分配给单个字节,因此出现错误 请尝试以下代码: byte[] imgarray = new byte[imglength]; 结构是这样的 byte[] Buffer = new byte[imglength]; 不能将字节数组分配给字节 试试这个
int imglength = FileUpload2.PostedFile.ContentLength;
byte imgarray=new byte[imglength];
您试图将字节数组(
byte[]
)分配给单个字节,因此出现错误
请尝试以下代码:
byte[] imgarray = new byte[imglength];
结构是这样的
byte[] Buffer = new byte[imglength];
不能将字节数组分配给字节 试试这个
byte[] bytearray = new byte[imglength];
您可以使用以下代码:
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转换为字节流请检查:
int imgLength = FileUpload2.PostedFile.ContentLength;
byte[] revLength= BitConverter.GetBytes(imgLength);
Array.Reverse(revLength);
byte[] imgLengthB = revLength;
byte
与byte[]
不同。第一个是字节,第二个是字节数组。尝试byte[]imgarray=新字节[imglength]
如果您发布代码、XML或数据示例,请在文本编辑器中突出显示这些行,并单击编辑器工具栏上的“代码示例”按钮({}
),以很好地格式化和语法突出显示它!