Hashtable.Keys.CopyTo(Array,int)方法只能拷贝一维数组吗?能不能拷贝二维数组呢?
2006-03-21 11:15
302 查看
根据微软的文档说明:
将 Hashtable 元素复制到一维 Array 实例中的指定索引位置。
[C#]
public virtual void CopyTo(
Arrayarray,
intarrayIndex
);
一维 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);
将 Hashtable 元素复制到一维 Array 实例中的指定索引位置。
[C#]
public virtual void CopyTo(
Arrayarray,
intarrayIndex
);
参数
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);
相关文章推荐
- java数组的拷贝四种方法:for、clone、System.arraycopy、arrays.copyof
- java数组的拷贝四种方法:for、clone、System.arraycopy、arrays.copyof
- java数组的四种拷贝方法的性能分析:for、clone、System.arraycopy、Arrays.copyof
- 数组拷贝 Array.copyof()方法与 System.arraycopy()方法
- C++ Daily 《4》----一个简单的 int to string 的方法
- java System.arraycopy的使用方法
- Python中的复制操作及copy模块中的浅拷贝与深拷贝方法
- C# 实现 int[]到string[]的转换方法 Array.ConvertAll
- SVN the working copy needs to be upgraded svn 低版本SVN检出代码,高版本SVN提交不了解决方法
- System.arraycopy的使用方法详解
- A method to realize deep copy of Hashtable
- Java ArrayList.toArray(T[]) 方法的参数类型是 T 而不是 E的原因分析
- java的system.arraycopy()方法
- 将二维数组转为一维数组的2种方法
- [置顶] C++/C#中堆栈、对象内存模型、深浅拷贝、Array.Clone方法
- mingw编译SDL_gfx库时遇到undefined reference to 'GFX_ALPHA_ADJUST_ARRAY'问题的解决方法
- java.util.ArrayList.toArray(T[]) 方法实例
- java类库中的System.arraycopy()方法
- text().toInt(&ok)获取标签控件字符串的方法
- C++(union), C#(伪union)实现 Java的Float.intBitsToFloat()方法