using ArrayList Collection Class

G

Guest

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
 
I

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

Hi,

You cannot initialize it that way , if it's an instance variable.

A possible solution would be

ArrayList myArrayList = new ArrayList( new String[] { "str 1" , "str 2" } )


Cheers,
 

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