开发者

Simple generic collection to add elements

开发者 https://www.devze.com 2023-04-04 06:06 出处:网络
What collection should I use from C# that suports generic only for adding elements ? I tried using ArrayList, but I s开发者_开发百科ee that it\'s a non-generic type.

What collection should I use from C# that suports generic only for adding elements ? I tried using ArrayList, but I s开发者_开发百科ee that it's a non-generic type.

Sorry if this is a duplicate. Thanks.


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#


System.Collections.Generic.List<T>


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

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

Hope this helps


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号