Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. static class and Serialization

static class and Serialization

Scheduled Pinned Locked Moved C#
questioncsharpjsonhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sendilkumar M
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • S Sendilkumar M

      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

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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; }

      J 1 Reply Last reply
      0
      • G Guffa

        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; }

        J Offline
        J Offline
        Josh Smith
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups