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?
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 ();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With