如何int数组值复制到字节数组?仅在C#中的值复制 [英] How to copy int array value into byte array? only copy the value in C#

查看:95
本文介绍了如何int数组值复制到字节数组?仅在C#中的值复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有这种阵列的

  INT [] = arrayint新INT [32];

和它包含

  arrayint [0] = 99
arrayint [1] = 121
arrayint [2] = 99
arrayint [3] = 66
...

有一个简单的方法来该整数数组复制到一个字节数组像我想使这个字节数组

 字节[] streambit;

和它应该是相同的arrayint值

我想是这样的输出

  streambit [0] = 99
streambit [1] = 121
streambit [2] = 99
streambit [3] = 66
...


解决方案

  streambit = arrayint.Select(I =>(字节)I).ToArray();

只要确保你没有比255更大的价值。

hi i have this kind of array

int[] arrayint = new int[32];

and it contains

arrayint[0] = 99
arrayint[1] = 121
arrayint[2] = 99
arrayint[3] = 66
...

is there a simple way to copy that integer array into a byte array like i want to make this byte array

byte[] streambit;

and it should be the same to the arrayint value

i want to be like this the output

streambit[0] = 99
streambit[1] = 121
streambit[2] = 99
streambit[3] = 66
...

解决方案

streambit = arrayint.Select(i => (byte)i).ToArray();

Just make sure that you have no value greater than 255.

这篇关于如何int数组值复制到字节数组?仅在C#中的值复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆