0
我試圖找到Decombine字節數組轉換爲它的兩個初始者的好方法:C#合併/ Decombine兩個字節數組
我使用合併日兩個字節數組:
public static byte[] Combine(params byte[][] arrays)
{
byte[] rv = new byte[arrays.Sum(a => a.Length)];
int offset = 0;
foreach (byte[] array in arrays)
{
System.Buffer.BlockCopy(array, 0, rv, offset, array.Length);
offset += array.Length;
}
return rv;
}
和decombining他們使用:
public static object[] DeCombine(byte[] array, int first)
{
byte[] f = new byte[first];
byte[] s = new byte[(array.Length - first)];
Array.Copy(array, f, array.Length - (array.Length - first));
Array.Copy(array, s, array.Length - first);
return new[] { f, s };
}
但這並不似乎是工作,對於第一陣列我得到的所有它完美的必要字節,但對於陣列Seconde系列(byte[] s
) 我不明白。
我試過了,通過梳理兩個文件的字節 file1.txt => containe text =「LM LM LM」; FILE2.TXT => containe文本=「哎;
我得到用於第一陣列FILE1.TXT的全部字節; 但FILE2.TXT =>我只得到:‘L’ 我想念提前瞭解些什麼呢?還是失去了一些東西?
感謝。
請注意int first
是第一陣列組合