zoukankan      html  css  js  c++  java
  • Hashtable.Keys.CopyTo(Array,int)方法只能拷贝一维数组吗?能不能拷贝二维数组呢?

    根据微软的文档说明:
    Hashtable 元素复制到一维 Array 实例中的指定索引位置。
    [C#]
    public virtual void CopyTo(
       Array array,
       int arrayIndex
    );

    参数

    array
    一维 Array,它是从 Hashtable 复制的 DictionaryEntry 对象的目标位置。Array 必须具有从零开始的索引。
    arrayIndex
    array 中的从零开始的索引,从此处开始复制。

    但是通过实践能实现二维数组的拷贝,在这里实现二维数组的拷贝:
    相关代码如下:
       Hashtable ht = new Hashtable();   
       int[][] a = new int[1][];
       a[0] = new int[1]{1};
       int[][] b = new int[1][];
       b[0] = new int[3]{0,1,2};
       int[][] c = new int[2][];
       c[0]  = new int[3]{1,2,3};
       c[1] = new int[2]{3,4};
       ht[a[0]] = a[0];
       ht[b[0]] = b[0];
       ht[c[0]] = c[0];
       ht[c[1]] = c[1];
       int[][]d = new int[ht.Count][];
       ht.Keys.CopyTo(d,0);

  • 相关阅读:
    函数进阶-生成器
    函数进阶-列表生成式
    闭包
    命名空间
    内置方法
    函数
    squid清除缓存
    subprocess实现管道
    Python统计脚本行数(fileinput)
    fabric note
  • 原文地址:https://www.cnblogs.com/flashwave/p/354690.html
Copyright © 2011-2022 走看看