如何在C#中将int [,]转换为byte [] [英] How to convert an int[,] to byte[] in C#
本文介绍了如何在C#中将int [,]转换为byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C#中将int [,]转换为byte []? 一些代码将不胜感激
How to convert an int[,] to byte[] in C#? Some code will be appreciated
我需要一个函数来执行以下操作:
I need a function to perform the following:
byte[] FuncName (int[,] Input)
推荐答案
由于您的问题很少,我只能猜测您要执行的操作...假设您要展平" 2D将整数数组转换为一维字节数组,您可以执行以下操作:
Since there is very little detail in your question, I can only guess what you're trying to do... Assuming you want to "flatten" a 2D array of ints into a 1D array of bytes, you can do something like that :
byte[] Flatten(int[,] input)
{
return input.Cast<int>().Select(i => (byte)i).ToArray();
}
请注意对Cast
的调用:这是因为多维数组实现了IEnumerable
而不是IEnumerable<T>
Note the call to Cast
: that's because multidimensional arrays implement IEnumerable
but not IEnumerable<T>
这篇关于如何在C#中将int [,]转换为byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文