using ArrayList Collection class

G

Guest

(Sorry if this is a re-post, don't think it worked the first time)

Hello,

I am trying to add an ArrayList as a field in my web form class.

Here is a sample:

using System;
using System.Collections;
....

ArrayList myArrayList = new ArrayList();
myArrayList.Add("Belleck Colleen Vase");
myArrayList.Add("Belinda Bradshaw Cat Bowl");
myArrayList.Add("Nicholas Mosse Cat Mug");
myArrayList.Add("Shamrock Paperweight");
myArrayList.Add("Business Card Holder");

When trying to build this web form I get the error
"Invalid tocken '(' in class, struct, or interface member declaration"

Does anyone know why I can't add an ArrayList as a field in my web form
class? I want to be able to access my ArrayList in different methods within
my web form.

Thanks
 
A

Alex Li

Diatom,

Seems like you have an extra ( in your code somewhere.... it is
probably just syntax error, not anything related to ArrayList at all.

HTH,
Alex
 
B

Barry Kelly

myArrayList.Add("Belleck Colleen Vase");
myArrayList.Add("Belinda Bradshaw Cat Bowl");
myArrayList.Add("Nicholas Mosse Cat Mug");
myArrayList.Add("Shamrock Paperweight");
myArrayList.Add("Business Card Holder");

You can only put these statements in a method body. You must implement an
event, override a method, or create a new method and place these
statements inside the method body.

-- Barry
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Use an array instead. if you know a priori the content of it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top