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. HOW TO SAVE AN OBJECT TO A FILE WITH C#

HOW TO SAVE AN OBJECT TO A FILE WITH C#

Scheduled Pinned Locked Moved C#
csharphelptutorial
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.
  • D Offline
    D Offline
    dexom
    wrote on last edited by
    #1

    I have a student class with attributes: name, id,... And I want to save it to a file then restore it. I don't know how to do that. Please help me.Thanks

    A T 2 Replies Last reply
    0
    • D dexom

      I have a student class with attributes: name, id,... And I want to save it to a file then restore it. I don't know how to do that. Please help me.Thanks

      A Offline
      A Offline
      Angel Reyes
      wrote on last edited by
      #2

      Take a look at Serialization[^]

      1 Reply Last reply
      0
      • D dexom

        I have a student class with attributes: name, id,... And I want to save it to a file then restore it. I don't know how to do that. Please help me.Thanks

        T Offline
        T Offline
        TylerBrinks
        wrote on last edited by
        #3

        First you need to mark your class with the [Serializable] attribute so the fields/properties can be mapped to your output file. To write the file youve got a few options. First, you can use an XmlSerializer and TextWriter to write the file as XML formatted text. You can write the file as as Binary file using the FileStream and BinaryFormatter classes.

        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