如何将对象数组添加到arraylist [英] How to add object array to the arraylist
问题描述
大家好
我想在我的项目中将对象[]添加到数组列表中,如下所示:
object [] obj = {111,Sara,200,300}
并定义:
arrayList arr = new arrayList(200);
this.arr.Insert(k,obj);
k ++;
我尝试过的事情:
我用过this.arr.add()但不起作用
Hi All
I wanna Add object[] to array list in my Project as Follow :
object[] obj= {"111","Sara","200","300"}
and define :
arrayList arr = new arrayList(200);
this.arr.Insert(k,obj);
k++;
What I have tried:
I used this.arr.add() but does not work
推荐答案
这里有两个直接问题,一个是间接问题。
1)ArrayList
与arrayList
不同 - C#区分大小写。
2)您将arr声明为局部变量 - 表示它的范围是声明它的方法。你不能通过类实例访问它,这是这个
的用途。
There are two direct problems here, and one indirect.
1)ArrayList
is not the same asarrayList
- C# is case sensitive.
2) You declare arr as a local variable - which means it is scoped to the method in which it is declared. You cannot access it via the class instance, which is whatthis
is there for.
ArrayList arr = new ArrayList(200);
arr.Add(obj);
间接问题是ArrayList在C#的V2中被取代,waaaay回来了2005年由Generic Collections提供,因为它们是类型安全的,它们要好得多。不应在新项目中使用ArrayList。
The indirect problem is that ArrayList was superseded in V2 of C#, waaaay back in 2005 by Generic Collections, which are a lot better as they are typesafe. ArrayList should not be used in new projects.
这篇关于如何将对象数组添加到arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!