本文介绍了在 C# 中将字节数组转换为短数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在读取一个文件,并希望能够将从文件中获取的字节数组转换为一个短数组.
I'm currently reading a file and wanted to be able to convert the array of bytes obtained from the file into a short array.
我该怎么做?
推荐答案
一种可能性是使用 Enumerable.Select
:
One possibility is using Enumerable.Select
:
byte[] bytes;
var shorts = bytes.Select(b => (short)b).ToArray();
另一个是使用 Array.ConvertAll
:
Another is to use Array.ConvertAll
:
byte[] bytes;
var shorts = Array.ConvertAll(bytes, b => (short)b);
这篇关于在 C# 中将字节数组转换为短数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!