在C#中追加数组 [英] Appending Array in C#

查看:106
本文介绍了在C#中追加数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个数组



say I have an array

byte[] a = File.ReadAllBytes("a.doc");
byte[] b = File.ReadAllBytes("b.doc"); 





如何将这两个数组组合成一个数组,使得两个数组都应该存在于新数组中?



how to combine these 2 array into one array in such a way that both array should be there on new array?

推荐答案

使用列表并使用AddRange添加每个数组然后转换回数组

Use a list and add each array using AddRange then convert back to an array
List<byte> list = new List<byte>();
list.AddRange(a);
list.AddRange(b);

byte[] c= list.ToArray();


你好Faisalabadians。



关于CHill60的解决方案 - 很好&简单(你得到我的5岁以上)



如果性能很重要,如果你可以使用IEnumerable< byte>,肯定更喜欢Linq' 's Concat<>方法。



Hi Faisalabadians.

about the solution of CHill60 - nice & simple (you got my 5+)

If performance is important and if you can use an IEnumerable<byte>, definitely prefer Linq''s Concat<> method.

IEnumerable<byte> Con_A_and_B = a.Concat(b);





干杯,

Edo



Cheers,
Edo





查看这两个链接以获得答案:

如何组合两个字节数组

在C#中组合两个或多个字节数组的最佳方法



谢谢
Hi,

Checkout these two links for your answer:
How to combine two byte arrays
Best way to combine two or more byte arrays in C#

Thanks


这篇关于在C#中追加数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆