Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法隐式转换';字节[]和#x27;至';字节';_C#_.net - Fatal编程技术网

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或数据示例,请在文本编辑器中突出显示这些行,并单击编辑器工具栏上的“代码示例”按钮(
{}
),以很好地格式化和语法突出显示它!