Hi,
I have to serialize a class which consists of numerous members in it. I know that it can be serialized with the [Serializable] attribute. But my problem is that I wanna serialize only few members. Is there any way that allows us to serialize only few members in a class?
Please help.
Decorate the fields you want to exclude with [NonSerialized] .
You can include the [NonSerialized] attribute for the members which you do not wish to be serialized as shown below.
[Serializable]
class ABC
{
int x;
int y;
[NonSerialized]int z;//z will not be serializable.
}
I hopw this helped you.
SrikanthReddy.L
0 comments:
Post a Comment