如何把一个array复制到arrayList里?
2010-06-02 15:06
399 查看
方法一、使用foreach循环,将array数组中的数据逐步放入ArrayList的对象中;
方法二、使用Copy方法,进行数据的复制;
方法三、使用ArrayList的adpater的方法 ,将整个Array对象封装到ArrayList对象中。
// author:renfuming
public static void Main(string[] renargs)
{
int[] arrayInt=new int[]{1,2,3,4};
ArrayList arrlistInt=new ArrayList();
//方法一
foreach(int a in arrayInt)
{
arrlistInt.Add(a);
}
Console.WriteLine(arrlistInt[2].ToString());//输出3
//方法二:
ArrayList arrlistInt2=new ArrayList();
arrlistInt2=ArrayList.Adapter(arrayInt);
Console.WriteLine(arrlistInt2[2].ToString());//输出3
//逆向转换
Array resultArr=(int[])arrlistInt2.ToArray(typeof(int));
Console.WriteLine(resultArr.GetValue(2));//输出3
}
方法二、使用Copy方法,进行数据的复制;
方法三、使用ArrayList的adpater的方法 ,将整个Array对象封装到ArrayList对象中。
// author:renfuming
public static void Main(string[] renargs)
{
int[] arrayInt=new int[]{1,2,3,4};
ArrayList arrlistInt=new ArrayList();
//方法一
foreach(int a in arrayInt)
{
arrlistInt.Add(a);
}
Console.WriteLine(arrlistInt[2].ToString());//输出3
//方法二:
ArrayList arrlistInt2=new ArrayList();
arrlistInt2=ArrayList.Adapter(arrayInt);
Console.WriteLine(arrlistInt2[2].ToString());//输出3
//逆向转换
Array resultArr=(int[])arrlistInt2.ToArray(typeof(int));
Console.WriteLine(resultArr.GetValue(2));//输出3
}
相关文章推荐
- 如何把一个Array 复制到ArrayList中?
- 如何把一个 Array 复制到 ArrayList 里?
- java中如何把一个array复制到arrayList里
- 如何把一个array复制到arrayList里
- 如何把一个array复制到arrayList里
- 在Java中如何将一个数组Array转换为ArrayList
- 如何将Array复制到ArrayList里面
- 如何把一个Array放到一个ArrayList中
- 如何只复制一个表结构
- 如何深度复制一个javascript对象
- 如何复制一个SQL Server 的表
- Linux/Unix 中如何在复制一个目录时排除其中的某个文件
- SQL中如何将一个表中的某一列的数据复制到另一个表中的某一列里
- SQL中如何将一个表中的某一列的数据复制到另一个表中的某一列里
- 如何把java中的arrayList转化为oracle中的数组(array) --转
- System.arraycopy()从指定源数组中复制一个数组
- matlab如何将一个文件夹下内容复制到另一个文件夹下
- Swift3中如何为Array写一个限定Type的扩展
- windows.setparent可以将一个窗口显示到别的位置上,可是如果我只是想将这个窗口上的内容复制一份并显示在别的位置,该如何做呢?
- Flex中如何将一个数组Array作为Tree的数据提供元