马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

C#合并两个数组方法

[复制链接]
查看3735 | 回复1 | 2016-12-9 10:11:25 | 显示全部楼层 |阅读模式
[C#] 纯文本查看 复制代码
byte[] b1 = new byte[] { 1, 2, 3, 4, 5 };
            byte[] b2 = new byte[] { 6, 7, 8, 9 };
            byte[] b3 = new byte[b1.Length + b2.Length];
            char[] b4 = new char[] { '1', '2', '3', '4', '5' };
            char[] b5 = new char[] { '6', '7', '8', '9' };
            char[] b6 = new char[b1.Length + b2.Length];
            int[] b7 = new int[] { 1, 2, 3, 4, 5 };
            int[] b8 = new int[] { 6, 7, 8, 9 };
            int[] b9 = new int[b1.Length + b2.Length];
            string[] b10 = new string[] { "1", "2", "3", "4", "5" };
            string[] b11 = new string[] { "6", "7", "8", "9" };
            string[] b12 = new string[b1.Length + b2.Length];


            Buffer.BlockCopy(b1, 0, b3, 0, b1.Length);//这种方法仅适用于字节数组
            Buffer.BlockCopy(b2, 0, b3, b1.Length, b2.Length);
            b7.CopyTo(b9, 0);//这种方法适用于所有数组
            b8.CopyTo(b9, b7.Length);
            b6 = b4.Concat(b5).ToArray();//这种linq方法适用于所有数组,狠,一句话搞定
            foreach (var item in b3)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
            foreach (var item in b6)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();
            foreach (var item in b9)
            {
                Console.Write(item + " ");
            }
            Console.ReadKey();
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
剑弑 | 2016-12-9 10:15:57 | 显示全部楼层
6666
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则