如何将字节数组转换为int数组? [英] How to Convert a byte array into an int array?
本文介绍了如何将字节数组转换为int数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将字节数组转换为int数组?我有一个字节数组,其中包含144个项目,由于我的经验不足,我尝试的方法效率很低.很抱歉,如果以前已经回答过,但是在任何地方都找不到很好的答案.
How to Convert a byte array into an int array? I have a byte array holding 144 items and the ways I have tried are quite inefficient due to my inexperience. I am sorry if this has been answered before, but I couldn't find a good answer anywhere.
推荐答案
简单:
//Where yourBytes is an initialized byte array.
int[] bytesAsInts = yourBytes.Select(x => (int)x).ToArray();
确保在使用声明中包括System.Linq
:
Make sure you include System.Linq
with a using declaration:
using System.Linq;
如果不是LINQ,您可以改用它:
And if LINQ isn't your thing, you can use this instead:
int[] bytesAsInts = Array.ConvertAll(yourBytes, c => (int)c);
这篇关于如何将字节数组转换为int数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文