Click here to Skip to main content
15,846,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);

What I have tried:

I used this.arr.add() but does not work
Updated 26-Nov-17 22:42pm

1 solution

There are two direct problems here, and one indirect.
1) ArrayList is not the same as arrayList - 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 what this is there for.
ArrayList arr = new ArrayList(200);

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.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900