Creating a sequential-access file : Binary Read Write : File Stream C# Source Code


Custom Search

C# Source Code » File Stream » Binary Read Write »

 

Creating a sequential-access file








    


   using System;
   using System.Data;
   using System.IO;
   using System.Runtime.Serialization.Formatters.Binary;
   using System.Runtime.Serialization;

   public class CreateFile {
      static void Main() {
         BinaryFormatter formatter = new BinaryFormatter();
         FileStream output = new FileStream( "test.dat",FileMode.OpenOrCreate, FileAccess.Write );
         Record record = new Record();
         record.Account = 1234;
         record.FirstName = "FirstName";
         record.LastName = "LastName";
         record.Balance = 1234.345;

         formatter.Serialize( output, record );
         output.Close();
      }
   }
   
   [Serializable]
   public class Record{
      public int Account;
      public String FirstName;
      public String LastName;
      public double Balance;
   }

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo File Stream
» Binary Read Write