<p>Put differently:</p>

<p>Is there a good reason to choose a loosely-typed collection over a type-safe one (HashTable vs. Dictionary)? Are they still there only for compatibility?</p>

<p>As far as I understand, generic collections not only are type-safe, but their performance is better.</p>

<hr>

<p>Here's a comprehensive article on the topic: <a href="http://msdn.microsoft.com/en-us/library/ms364091%28VS.80%29.aspx" rel="noreferrer">An Extensive Examination of Data Structures Using C# 2.0</a>.</p>

[{'answer_id': 56378, 'author': 'Mark Ingram', 'author_id': 986, 'author_profile': 'https://Stackoverflow.com/users/986', 'pm_score': 0, 'selected': False, 'text': '<p>Yes, as far as I understand they are only there for compatibility with existing products. You should always use the type safe version (i.e. use System.Collections.Generic over System.Collections).</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms379564.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms379564.aspx</a></p>\n'}, {'answer_id': 56380, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 6, 'selected': True, 'text': "<p>The non-generic collections are so obsolete that they've been removed from the CoreCLR used in Silverlight and Live Mesh.</p>\n"}, {'answer_id': 56381, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 1, 'selected': False, 'text': '<p>There might be instances where you need to store objects of unknown types, or objects of multiple different types, but if you do indeed know the type of the objects that you want to store then I cannot see a reason not to use the generic version.</p>\n\n<p>Edit: As commented you can just use <code>List&lt;Object&gt;</code> - doh!</p>\n'}, {'answer_id': 56382, 'author': 'Sean Chambers', 'author_id': 2993, 'author_profile': 'https://Stackoverflow.com/users/2993', 'pm_score': 4, 'selected': False, 'text': '<p>Going forward only generic collections should be used. There is also the benefit of avoiding boxing/unboxing of types in the collection. This is ineffecient, especially when you have a collection of value types that are converted to System.Object when stored on the collection, hence storing the values on the heap instead of the callstack.</p>\n'}, {'answer_id': 56393, 'author': 'Mel', 'author_id': 1763, 'author_profile': 'https://Stackoverflow.com/users/1763', 'pm_score': 3, 'selected': False, 'text': '<p>With regard to using non-generic collections for storing heterogeneous collections of stuff, you can always use List&lt;object&gt; to accomplish the same thing.  For this reason alone, I\'d say there\'s almost no reason at all to touch the non-generic collections ever again.</p>\n\n<p>The exception to this would be to maintain compatibility with systems written in other languages, or against previous versions of the .NET framework, but that\'s a pretty "edgy" case if you ask me.</p>\n'}, {'answer_id': 56397, 'author': 'Martin Marconcini', 'author_id': 2684, 'author_profile': 'https://Stackoverflow.com/users/2684', 'pm_score': 1, 'selected': False, 'text': "<p>I wouldn't jump and say that are obsolete or are going to be removed anytime soon. \nIt's true that you should avoid using non-generic collections unless you have a reason <strong>not</strong> not use a generic version. Thousands of lines of legacy (not so legacy) code is still floating around (and will be for years) that support non-generic collections such as ArrayLists. Since these were the <em>only</em> collections in .NET 1.0 and 1.1, it has been widely used (and abused) throughout the year. </p>\n\n<p>I still occasionally have to interact with an old O/R mapper written in .NET 1.1 that returns IList objects. I have a method that does the conversion to a generic List&lt;>, which is not efficient, but that's the way it is. </p>\n\n<p>And if you need to store different objects in the same array (weird but possible) you <strong>will</strong> need a non-generic collection. The penalty of Boxing and Unboxing is something you'll have to pay anyway.</p>\n\n<p>Don't be afraid to use them if you feel that you have to.</p>\n"}, {'answer_id': 56422, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>I can tell you that XAML serialization of collections rely on them implementing either IList or IDictionary, so non-generic collections are going to be with us for some time to come.</p>\n'}, {'answer_id': 56517, 'author': 'Tony Lee', 'author_id': 5819, 'author_profile': 'https://Stackoverflow.com/users/5819', 'pm_score': 4, 'selected': False, 'text': "<p>There are also issues with COM visibility - COM interop can't be used with generics</p>\n"}, {'answer_id': 70542386, 'author': 'user17804168', 'author_id': 17804168, 'author_profile': 'https://Stackoverflow.com/users/17804168', 'pm_score': 0, 'selected': False, 'text': "<p>It's almost 2022, and I'm having to write a COM Visible Non-Generic collection class for consumption by a large front end commercially used program written in VB6 - the prime example of such a consumer for non generic collection classes.  So I don't see the need for these types of class disappearing any time soon, as there is still a lot of active VB6 code out there.</p>\n<p>Meanwhile, use ArrayList and IList to underpin the custom collection class, and check that the individual items are of the type you expect before processing them, e.g.</p>\n<p>[ComVisible(true)]\npublic class MyNonGenericCollection : ArrayList, IList\n{\nprivate ArrayList myList = new ArrayList();</p>\n<p>...</p>\n<pre><code>public int Add(object myItem)\n{\n    if (!(myItem is MyItemClass))\n        throw new ArgumentException(nameof(myItem));\n\n    // code to add to the ArrayList\n</code></pre>\n<p>}</p>\n"}]
['https://Stackoverflow.com/questions/56375', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1670/']