如何划分C#的数组? [英] How to Divide an array on c#?
问题描述
我要做的读取和图像,并把它放到一个字节数组程序
I have to do a program that read and image and puts it into a byte array
VAR Imagenoriginal = File.ReadAllBytes(10M.bmp);
和除以字节数组转换为3 Diferent阵列为了发送该新阵列中其他计算机的每一个(使用管道)在那里处理它们,最后把他们回到origial计算机最后给出结果。
但我的问题是我做的一个算法能够把字节数组分为三种不同的字节数组,如果选择的图像可以有diferent大小怎么做。
感谢您的帮助,有一个愉快的一天。 =)
And Divide That byte Array into 3 Diferent Arrays in order to send each one of this new arrays to other computer ( Using Pipes ) to process them there and finally take them back to the origial computer and finally give the result. But my question Is how do I do an Algorithm able to divide the byte array in three different bytes arrays if the image selected can have diferent size. Thanks for your help, have a nice day. =)
推荐答案
您可以将数组的长度,所以你有三个整数 N1
, N2
和 N3
与他们总结到 array.Length
。然后,这个片段中,使用LINQ应该是帮助:
You can divide length of array, so you have three integers n1
, n2
and n3
with all of them summing up to array.Length
. Then, this snippet, using LINQ should be of help:
var arr1 = sourceArray.Take(n1).ToArray();
var arr2 = sourceArray.Skip(n1).Take(n2).ToArray();
var arr3 = sourceArray.Skip(n1+n2).Take(n3).ToArray();
现在,在 ARR1
, ARR2
和 ARR3
你将有你的源阵列三部分组成。您需要使用LINQ,所以在code的开始,不要忘记使用System.Linq的;
Now, in arr1
,arr2
and arr3
you will have three parts of your source array. You need to use LINQ, so in the beginning of the code don't forget using System.Linq;
.
这篇关于如何划分C#的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!