Can we serialize the object which uses HashTables.
It depends on the type of object that you are storing in the Hashtable.
If you are storing objects like string (or whatever which is marked with attribute serializable), then you can look thro the objects to serialize them one by one.
r.ramkumar:
Can we serialize the object which uses HashTables.
Yes, as long as the indivdual objects in the hash table are serializable (as the previous poster points out). Then all you have to do is serialize your hashtable, you don't have to loop through, serializing each individual object. If you take a look at the definition of Hashtable athttp://msdn2.microsoft.com/en-us/library/system.collections.hashtable(VS.71).aspx you'll see that it's marked as [Serializabl] and it implements the ISerializable interface.
Most objects that you would wish to put into a hashtable are serializale. An example of something that isn't is a DataReader, and if you think about it, there's no way that a DataReader could be put into a stream of text since it holds a connection to the database. Connections (to anything) are perfect examples of things that aren't serializable.
Sometimes you create a custom class and try to serialize it (or save it to an asp.net State server, which requires that it be serializable) and you get an error that it's not serializable. Just try decorating your class with the [Serializable] attribute, for example
[Serializable]
public class MyClass
{
....blah, blah
}
(note that in vb you use angle brackets instead of straight brackets, ie, <Serializable> instead of [Serializable]
I just reread your post and realize that I misunderstood it. The object you want to serialize uses a hashtable (I thought you were just trying to serialize something of type Hashtable). My answer is the same but pay special attention to the last half, the part beginning "Sometimes you create a custom class..." which I think is what will really answer your question.
0 comments:
Post a Comment