Why Dictionary is preferable to Hashtable in C#? Analyzing the differences
Hello everyone! I'm a beginner C# developer and encountered a situation that confused me. While studying collections, I came across two similar classes: `Hashtable` and `Dictionary`. Both, as I understand, store key-value pairs and allow quick data lookup by key.\n\nIn old code examples and some books, I often see `Hashtable`. For example, like this:\n\n```csharp\nHashtable table = new Hashtable();\ntable.Add("key1", "value1");\ntable.Add(123, 42); // key — int, value — int\nstring val = (string)table["key1"]; // explicit casting required\n```\n\nBut in modern projects and on Stack Overflow, everyone writes about `Dictionary`. I tried both options and noticed that with `Dictionary` the code looks different:\n\n```csharp\nDictionary dict = new Dictionary
No answers yet.
Log in to leave an answer