0

I wrote this code private ArrayList articles = new ArrayList(); and it just won't compile. Visual Studio is giving me this error:

The type or namespace name 'ArrayList' could not be found (are you missing a using directive or an assembly reference?)

Yet i made sure to import the System.Collections Namespace. I even tried with

System.Collections.ArrayList articles = new ArrayList();

But no success either. Thanks for any help

23
  • 1
    System.Collections.ArrayList articles = new System.Collections.ArrayList(); would be the correct Syntax there. However it should have definitely worked if you have included a using statement of the appropriate namespace; only issue then could be that the assembly is not referenced at all in your project. Commented Aug 9, 2016 at 11:36
  • check here for definition and example msdn.microsoft.com/en-us/library/… Commented Aug 9, 2016 at 11:37
  • 2
    Are you using Metro app or UWP ? Then, they are gone. Use List<T> instead. Commented Aug 9, 2016 at 11:38
  • 2
    @MrinalKamboj There is no System.Collections.dll. The namespace "System.Collections" is defined in mscorlib.dll which should be included automatically as far as i know. Commented Aug 9, 2016 at 11:39
  • 1
    @Rakitić Thanks a lot Commented Aug 9, 2016 at 12:26

4 Answers 4

3

I know this is an old post, but this might help someone else. As of 2018 and Visual Studio 2017 you can use ArrayList. They are apart of the System.Collections namespace. All you have to do to use an ArrayList is import that namespace using the following:

Using System.Collections; 

After you import this namespace you can use ArrayList, Stacks, Queues, and a few other goodies.

To declare an ArrayList you would use the following syntax

ArrayList variable = new ArrayList();
Sign up to request clarification or add additional context in comments.

Comments

1
List<List Item> list = new List<List Item>();

You can use this code for .net version higher than 4.0. * avoid spaces between List and Item inside <> on both sides...

Comments

0

If you are using Framework 4.0 or higher Arraylist() is not available.You need to use the available Generic List

1 Comment

Finally they removed ArrayList. (I missed the memo). I am tired of seing "expert" [c#] programmers use ArrayList.
-2
System.Collections.ArrayList articles = new System.Collections.ArrayList();

This is correct syntax

1 Comment

The autocomplete feature doesn't even suggest ArrayList when i type System.Collections.Arr and then it Ctrl + Tab

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.