zoukankan      html  css  js  c++  java
  • c#复制数组的多种方法

    方法一:使用for循环
    int []pins = {9,3,7,2}
    int []copy = new int[pins.length];
    for(int i =0;i!=copy.length;i++)
    {
    copy[i] = pins[i];
    }
    方法二:使用数组对象中的CopyTo()方法
    int []pins = {9,3,7,2}
    int []copy2 = new int[pins.length];
    pins.CopyTo(copy2,0);
    方法三:使用Array类的一个静态方法Copy()
    int []pins = {9,3,7,2}
    int []copy3 = new int[pins.length];
    Array.Copy(pins,copy3,copy.Length);
    方法四:使用Array类中的一个实例方法Clone(),可以一次调用,最方便,但是Clone()方法返回的是一个对象,所以要强制转换成恰当的类类型。
    int []pins = {9,3,7,2}
    int []copy4 = (int [])pins.Clone();
    方法五:
    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" };
    ArrayList student = new ArrayList();    
    foreach (string s1 in student1)
    {
          student.Add(s1);                 
    }
    foreach (string s2 in student2)
    {
          student.Add(s2);
    }
    string[] copyAfter = (string[])student.ToArray(typeof(string));
  • 相关阅读:
    [SAM学习笔记]
    CF513G3 Inversions problem
    AtCoder Beginner Contest 204
    [SDOI2017]序列计数
    CF993E Nikita and Order Statistics
    多项式板子
    多项式杂学笔记
    「雅礼集训 2017 Day5」远行
    Mysql备份恢复工具
    个人选择上网的流量方式对比
  • 原文地址:https://www.cnblogs.com/fish7/p/4107894.html
Copyright © 2011-2022 走看看