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. please HELLPPPP...

please HELLPPPP...

Scheduled Pinned Locked Moved C#
tutorialcsharpc++com
2 Posts 2 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.
  • N Offline
    N Offline
    nedimg
    wrote on last edited by
    #1

    I have to make an application to write and read structures! I have to do it in c#! I know to do this in c/c++ but i have no idea how to do it in c#! for example, my structure is like this: (in C) struct Info { int password; string name; etc. }X; ( i used File *f, fopen etc..) how to write this into a file (*.dat) and the read them...in c# I found this example: http://www.codeproject.com/useritems/readwritestructstobinfile.asp but it seems to be difficult and there are some saying that is a terrible idea!

    M 1 Reply Last reply
    0
    • N nedimg

      I have to make an application to write and read structures! I have to do it in c#! I know to do this in c/c++ but i have no idea how to do it in c#! for example, my structure is like this: (in C) struct Info { int password; string name; etc. }X; ( i used File *f, fopen etc..) how to write this into a file (*.dat) and the read them...in c# I found this example: http://www.codeproject.com/useritems/readwritestructstobinfile.asp but it seems to be difficult and there are some saying that is a terrible idea!

      M Offline
      M Offline
      mikone
      wrote on last edited by
      #2

      Hi, add this using statement to your code: using System.Runtime.Serialization.Formatters.Binary; use this code to read the file: MyClass MyObject = null; BinaryFormatter binReader = new BinaryFormatter(); System.IO.Stream readStream = File.Open("c:\blah.dat", FileMode.Open); MyObject = (MyClass)binReader.Deserialize(readStream); readStream.Close(); and this one to write it: MyClass MyObject = new MyClass(); BinaryFormatter binWriter = new BinaryFormatter(); System.IO.Stream writeStream = File.Open("c:\blah.dat", FileMode.Create); binWriter.Serialize(writeStream, MyObject); writeStream.Close(); and this is the class (or struct) you want to write to a file... [Serializable] public class MyClass { string SomeString = null; int SomeInteger = 0; string AnotherString = null; }

      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