谁能告诉我怎么把两个数组合并到一个数组中去,最好附带上代码

解决方案 »

  1.   


    string[] student1 = { "$", "$", "c", "m", "d", "1", "2", "3", "1", "2", "3" }; 
    string[] student2 = { "0", "1", "2", "3", "4", "5", "6", "6", "1", "8", "16","10","45", "37", "82" }; 
    string[] student = new string[student1.Length+student2.Length]; 
    for (int i = 0; i < student1.Length; i++) 

    student[i] = student1[i]; 

    for (int i = 0; i < student2.Length; i++) 

    student[i+student1.Length] = student2[i]; 
      

  2.   

    string[] student1 = { "$", "$", "c", "m", "d", "1", "2", "3", "1", "2", "3" }; 
    string[] student2 = { "0", "1", "2", "3", "4", "5", "6", "6", "1", "8", "16","10","45", "37", "82" }; 
    List<string> list = new List<string>();
    list.AddRange(student1);
    list.AddRange(student2);
    string[] newstr = list.ToArray();
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Collections;
    using System.IO;namespace CSharpTest
    {
        
        class B
        {
            
            static void Main()
            {
                int[] arr1 = new int[] { 1, 2, 3 };
                int[] arr2 = new int[] { 4, 5, 6 };
                int[] arr = new int[arr1.Length + arr2.Length];
                Array.Copy(arr1, arr, arr1.Length);
                Array.Copy(arr2, 0, arr, arr1.Length, arr2.Length);
                for (int i = 0; i < arr.Length; i++)
                {
                    Console.WriteLine(arr[i]);
                }
            }
        } 
        
    }
      

  4.   

    数组有自己的方法:private void button1_Click(object sender, EventArgs e)
            {
                int[] x = new int[10];
                for (int i = 0; i < 10; i++)
                    x[i] = i;
                int[] d = new int[10];
                for (int i = 9, j = 0; i >= 0; i--, j++)
                    d[j] = i;
                int[] s = new int[20];
                x.CopyTo(s, 0);
                d.CopyTo(s, 10);
                foreach (int m in s)
                    Console.WriteLine(m);
            }
    三句搞定:
                int[] s = new int[20];
                x.CopyTo(s, 0);
                d.CopyTo(s, 10);
    有时候很简单的问题,人们容易习惯性地搞复杂
    就象上次有个贴子,讲他的下属自己编了个string.split函数,楼主问他为啥不用.net自带的split函数,他下属回答不知道有这个,还说.net真牛B,连 split也有-_-
      

  5.   

    string[] arr1 = { "1", "2", };
    string[] arr2 = { "2", "3"};
     string[] result = A(arr1, arr2,);
       
            public static string[] A(params string[][] arrays)
            {
                List<string> list = new List<string>();
                foreach (string[] arr in arrays)
                    list.AddRange(arr);
                return list.ToArray();
            }
      

  6.   

    可以看一下数组有个CopyTo的方法,参数记不清了,但可以起到合并的功能~
      

  7.   

    #include <stdio.h>
    #include "memory.h"
    int main()
    {
    int ar[3]={1,2,3};
    int br[3]={4,5,6};
    int cr[6];
    int*p=cr;
    memcpy(p,ar,3*sizeof(int)); 
    p+=3;
    memcpy(p,br,3*sizeof(int)); 
    for(int i=0;i<6;i++) 
    printf("cr的值为:%d\n",cr[i]); 
    return 0;
    }刚看了一个内存拷贝的,练练手