Search code examples
c#generic-collections

Simple generic collection to add elements


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.


Solution

  • 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#