2

What collection should I use from C# that suports generic only for adding elements ? I tried using ArrayList, but I see that it's a non-generic type.

Sorry if this is a duplicate. Thanks.

Suman Banerjee
  • 1,923
  • 4
  • 24
  • 40
Adrian
  • 19,440
  • 34
  • 112
  • 219
  • What use is a collection which is only "for adding elements"? What do you intend to do with this collection? – spender Sep 09 '11 at 12:05

4 Answers4

3
System.Collections.Generic.List<T>
PVitt
  • 11,500
  • 5
  • 51
  • 85
3

Basic generic collection is List<T>. It is in System.Collections.Generic namespace.

You can use it for example this way:

List<string> listOfStrings = new List<string>() { "This", "is", "list", "of", "strings" }

Here is all the generic collections in C#

2
List<T>, IEnumerable<T>, ..

Are these the kind of things you're looking for? I don't really understand the question.

Hope this helps

leppie
  • 115,091
  • 17
  • 196
  • 297
Team-JoKi
  • 1,766
  • 3
  • 15
  • 23
1

You're probably after List. If you want a collection of unique elements, consider HashSet instead.

Henry C
  • 4,781
  • 4
  • 43
  • 83