---
title: "Hashtable to Dictionary"  
description: "Hashtable to Dictionary"  
author: "Anonymous User"  
published: 2013-12-17  
updated: 2013-12-17  
canonical: https://www.mindstick.com/forum/1792/hashtable-to-dictionary  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Hashtable to Dictionary

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) a hashtable to disctionary and found a a [question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time) here: convert HashTable to [Dictionary](https://www.mindstick.com/articles/1500/hashtable-and-dictionary-in-c-sharp) in C#

```
public static Dictionary<K,V> HashtableToDictionary<K,V> (Hashtable table){    return table        .Cast<DictionaryEntry> ()        .ToDictionary (kvp => (K)kvp.Key, kvp => (V)kvp.Value);}
```

When I try to use it, there is an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) in [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap).[Cast](https://answers.mindstick.com/qa/97273/how-to-cast-a-baitcaster); [intellisense](https://answers.mindstick.com/qa/115739/why-is-intellisense-not-working-in-visual-studio-2026) does not show "Cast" as a valid method.

## Replies

### Reply by Pravesh Singh

Hi Ankita,

Enumerable.Cast doesn't exist in .NET 2, nor does most of the LINQ related methods (such as ToDictionary).

You'll need to do this manually via looping:

```
public static Dictionary<K,V> HashtableToDictionary<K,V> (Hashtable table){    Dictionary<K,V> dict = new Dictionary<K,V>();    foreach(DictionaryEntry kvp in table)        dict.Add((K)kvp.Key, (V)kvp.Value);    return dict;}
```


---

Original Source: https://www.mindstick.com/forum/1792/hashtable-to-dictionary

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
