ArrayList error

J

John Rogers

How do I fix this error?

ArrayList customerArray = new ArrayList();
customerArray.Add("Tester");
customerArray.Add("Testing");

Error 1 Invalid token '(' in class, struct, or interface member declaration
222 26


Thanks
 
A

Arne Vajhøj

John said:
How do I fix this error?

ArrayList customerArray = new ArrayList();
customerArray.Add("Tester");
customerArray.Add("Testing");

Error 1 Invalid token '(' in class, struct, or interface member declaration
222 26

Sounds as if you have put some code that belong inside
a method outside a method.

Arne
 
J

John Rogers

I dont get what you are saying, because if I do this

ArrayList someList = new ArrayList();
someList.Add("test");

I will get the same error.
 
A

Arne Vajhøj

John said:
I dont get what you are saying, because if I do this

ArrayList someList = new ArrayList();
someList.Add("test");

I will get the same error.

Look at this:

C:\>type z1.cs
using System;
using System.Collections;

public class Z1
{
ArrayList customerArray = new ArrayList();
customerArray.Add("Tester");
customerArray.Add("Testing");
}

C:\>csc /t:library z1.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.1433
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

z1.cs(7,22): error CS1519: Invalid token '(' in class, struct, or interface
member declaration
z1.cs(8,22): error CS1519: Invalid token '(' in class, struct, or interface
member declaration

C:\>type z2.cs
using System;
using System.Collections;

public class Z2
{
public void Foobar()
{
ArrayList customerArray = new ArrayList();
customerArray.Add("Tester");
customerArray.Add("Testing");
}
}

C:\>csc /t:library z2.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.1433
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.


C:\>

Arne
 
M

Mike

How do I fix this error?

ArrayList customerArray = new ArrayList();
customerArray.Add("Tester");
customerArray.Add("Testing");

Error 1 Invalid token '(' in class, struct, or interface member declaration
222 26

Thanks

John, can you post the complete code for this c# class. I see nothing
wrong with this code, so I expect something is wrong with the class/
method definition.

Regards, Mike...
 

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