Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to declare an ArrayList

I'm not able to declare an ArrayList. Here's my code. (I'd much rather use Lists, but I'm just trying to understand the concept of an ArrayList).

private void button1_Click(object sender, EventArgs e)
{
    ArrayList salesTotals = new ArrayList();
    decimal[] decimalSales = { 1000m, 2000m, 3000m };

    foreach (decimal singleSales in decimalSales)
    {
        salesTotals.Add(singleSales);
    }
}

When I compile this, I get this error:

'ArrayList' is a 'namespace' but is used like a 'type'

I'm using the namespace System.Collections (not .Generic)

What is causing this and how do I fix it?

like image 350
Ray Avatar asked Jul 01 '11 19:07

Ray


2 Answers

One of the namespaces in your project is ArrayList. This is causing the conflict.

Try changing the namespace, or fully qualifying it like this:

System.Collections.ArrayList salesTotals = new System.Collections.ArrayList ();
like image 92
agent-j Avatar answered Sep 25 '22 12:09

agent-j


It sounds like you are using the ArrayList within a namespace itself called ArrayList. The symbol is resolving to the namespace definition, which is invalid in the symbol's context, causing the error you describe.

like image 35
mdm Avatar answered Sep 25 '22 12:09

mdm