{"id":559,"date":"2023-09-08T19:40:28","date_gmt":"2023-09-09T01:40:28","guid":{"rendered":"https:\/\/kop.lat\/blog\/?p=559"},"modified":"2023-09-08T19:40:28","modified_gmt":"2023-09-09T01:40:28","slug":"list-of-most-common-collections-in-c","status":"publish","type":"post","link":"https:\/\/kop.lat\/blog\/list-of-most-common-collections-in-c\/","title":{"rendered":"List of most common Collections in C#"},"content":{"rendered":"\n<p>In C#, there are several common collection types provided by the .NET Framework for storing and managing groups of objects. <\/p>\n\n\n\n<p>Some common collection types in C#, as follows<\/p>\n\n\n\n<ol>\n<li><strong>Array<\/strong>: Arrays are fixed-size collections that can store elements of the same type. They have a fixed length and cannot be resized after initialization.<\/li>\n\n\n\n<li><strong>List\\<\/strong>: <code>List<\/code> is a dynamic array that can grow or shrink in size. It&#8217;s part of the System.Collections.Generic namespace and provides methods for adding, removing, and manipulating elements.<\/li>\n\n\n\n<li><strong>Dictionary\\<\/strong>: <code>Dictionary<\/code> is a key-value pair collection where you can store elements based on unique keys. It&#8217;s useful for fast lookups and is also part of the System.Collections.Generic namespace.<\/li>\n\n\n\n<li><strong>HashSet\\<\/strong>: <code>HashSet<\/code> is a collection of unique elements. It ensures that all elements are distinct and does not allow duplicates.<\/li>\n\n\n\n<li><strong>Queue\\<\/strong>: <code>Queue<\/code> represents a first-in-first-out (FIFO) collection. Elements are removed in the order they were added.<\/li>\n\n\n\n<li><strong>Stack\\<\/strong>: <code>Stack<\/code> represents a last-in-first-out (LIFO) collection. Elements are removed in the reverse order of their addition.<\/li>\n\n\n\n<li><strong>LinkedList\\<\/strong>: <code>LinkedList<\/code> is a doubly-linked list that allows efficient insertion and removal of elements at both ends and at specific positions.<\/li>\n\n\n\n<li><strong>ArrayList<\/strong>: <code>ArrayList<\/code> is a non-generic collection that can store elements of different types. It&#8217;s not type-safe and is generally less efficient than <code>List&lt;T&gt;<\/code>.<\/li>\n\n\n\n<li><strong>BitArray<\/strong>: <code>BitArray<\/code> represents a collection of bits and allows for efficient bitwise operations.<\/li>\n\n\n\n<li><strong>SortedSet\\<\/strong>: <code>SortedSet<\/code> is similar to <code>HashSet<\/code>, but it keeps elements in sorted order based on their natural ordering or a specified comparer.<\/li>\n\n\n\n<li><strong>SortedDictionary\\<\/strong>: <code>SortedDictionary<\/code> is similar to <code>Dictionary<\/code>, but it keeps key-value pairs in sorted order based on their keys.<\/li>\n\n\n\n<li><strong>NameValueCollection<\/strong>: <code>NameValueCollection<\/code> is used to store key-value pairs where the keys can have multiple values.<\/li>\n\n\n\n<li><strong>ObservableCollection\\<\/strong>: <code>ObservableCollection<\/code> is a specialized collection that implements the INotifyCollectionChanged interface, making it suitable for data binding in user interfaces.<\/li>\n\n\n\n<li><strong>Concurrent collections<\/strong>: These collections are designed for multi-threaded scenarios and include types like <code>ConcurrentQueue<\/code>, <code>ConcurrentStack<\/code>, <code>ConcurrentBag<\/code>, and <code>ConcurrentDictionary<\/code>.<\/li>\n\n\n\n<li><strong>Immutable collections<\/strong>: Immutable collections are collections whose contents cannot be modified after creation. They include types like <code>ImmutableList<\/code>, <code>ImmutableDictionary<\/code>, and <code>ImmutableHashSet<\/code>.<\/li>\n\n\n\n<li><strong>BlockingCollection\\<\/strong>: <code>BlockingCollection<\/code> is used for producer-consumer scenarios in multi-threaded applications. It provides thread-safe blocking operations.<\/li>\n\n\n\n<li><strong>Specialized collections<\/strong>: .NET also provides specialized collections like <code>KeyedCollection<\/code>, <code>ReadOnlyCollection<\/code>, and others for specific use cases.<\/li>\n<\/ol>\n\n\n\n<p> The choice of collection type depends on the specific requirements of the application, including<\/p>\n\n\n\n<ul>\n<li>\u00a0 \u00a0  the type of data to store<\/li>\n\n\n\n<li>\u00a0 \u00a0  the expected access patterns<\/li>\n\n\n\n<li>\u00a0 \u00a0  concurrency considerations<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In C#, there are several common collection types provided by the .NET Framework for storing and managing groups of objects. Some common collection types in C#, as follows The choice of collection type depends on the specific requirements of the application, including<\/p>\n","protected":false},"author":1,"featured_media":465,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[51,52],"tags":[53,57,99,18,98,58,54],"_links":{"self":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts\/559"}],"collection":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/comments?post=559"}],"version-history":[{"count":1,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts\/559\/revisions"}],"predecessor-version":[{"id":560,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/posts\/559\/revisions\/560"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/media\/465"}],"wp:attachment":[{"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/media?parent=559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/categories?post=559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kop.lat\/blog\/wp-json\/wp\/v2\/tags?post=559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}