I am an upper level Software Engineering student currently in a Data Structures and Algorithms class. Our professor wants us to write a program using the List structure found in the C++ STL. I have been trying to use C# more and more, and was wondering if the ArrayList structure in .NET is a good substitute for the STL List implementation.
7 Answers
You should be able to answer this question yourself. What is the implementation strategy used in STL lists? What is the one of ArrayList? Likewise, what is the abstract API presented by STL list (in terms of operations provided)? Compare this to STL List: what does the one provide that the other doesn't?
Comments
The ArrayList class is somewhat deprecated. It is from the .NET 1.0 times when generics did not exist yet.
You should use System.Collections.Generic.List instead. Like this:
List<int> myList = new List<int>(); myList.Add(1); myList.Add(2); System.Console.WriteLine(myList[0]); And yes, both of them are good substitutes. You should use the generic List though, since it is type safe and potentially quicker.
Comments
Thanks everyone
quertie, i mistyped and meant list instead of List...
the assignment is to use std::list to add polynomials using a list of simple structs, a struct that would hold the coefficient and the power of x...easy enough, I know, but since the class is supposedly language-independent, I wanted to try to use c#
Comments
The closest C# analogue of the std::list is System.Collections.List. Both are generic collections, and implement the standard list-type actions.
1 Comment
std::list is a linked list. So a much closer equivalent collection would be System.Collections.LinkedList<T>