static class and Serialization
-
static class in C# can accept serialization attribute. like
[Serializable]
static class MyStatic
{
static MyStatic()
{}
}
compiler will not give error. But my question is can i serialize static class.if so how i can do? M.Sendilkumar
-
static class in C# can accept serialization attribute. like
[Serializable]
static class MyStatic
{
static MyStatic()
{}
}
compiler will not give error. But my question is can i serialize static class.if so how i can do? M.Sendilkumar
You can't serialize a class, only an instance. An instance of that class would be serializable, but that is quite useless, as you can't create an instance of the class. I'm not sure if it's an oversight in the design that a static class can be serializable, or if it's intentional. It shouldn't cause any problem anyway. --- b { font-weight: normal; }
-
You can't serialize a class, only an instance. An instance of that class would be serializable, but that is quite useless, as you can't create an instance of the class. I'm not sure if it's an oversight in the design that a static class can be serializable, or if it's intentional. It shouldn't cause any problem anyway. --- b { font-weight: normal; }
Guffa wrote:
I'm not sure if it's an oversight in the design that a static class can be serializable, or if it's intentional.
I don't think the AttributeUsage attribute provides a way to specify that an attribute can be applied only to non-static classes. That's probably why Serializable can be applied to any class. Josh