zoukankan      html  css  js  c++  java
  • 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();
    JAVA&NET技术QQ群号:456257217有问题的可以在群里面提问。
  • 相关阅读:
    面向过程
    生成器
    迭代器
    装饰器
    函数及嵌套
    字符编码与文件操作
    linux_ssh
    LNMP
    BZOJ 3238: [Ahoi2013]差异
    BZOJ 3998: [TJOI2015]弦论
  • 原文地址:https://www.cnblogs.com/shiyh/p/15476243.html
Copyright © 2011-2022 走看看