Saturday, January 19, 2013

Can we serialize Hashtable and Dictionary in C#


Hashtable and Dictionary

No, we can not serialized Hashtable and Dictionary. There are two reason for that.


  • Hashtable and Dictionary both are implemented from IDictionay interface. We need XML serializer to serialize the Hashtable and Dictionary. XML serializer doesn't support IDictionay interface.

  • Hashtable and Dictionary both are implemented from IEnumerable interface. IEnumerable works with yield keyword. Basically compiler generate a separate class to implement yield functionality and generated class is not seriazible i.e. generated class is not marked as serializable.

1 comment: