read multiple struct from binary file in c# -


I want to insert data into a binary file. The data is 50 structure. I want to save the features of soft music files in binary. The file that the database can use.

I have created a straight for every song, and put it in the file. The structure is:

  public structures {public byte class_no; Public int sample_no; Public byte [] template; }  

Where the template is a 1-D array, my file of 4410 now has 50 structures and I want to read it using the binary file and make the straight of all strings in the file

I will answer many structs from the file.

Defines a structure to hold this example

None of these is designed for your specific needs but how to save it in a normal form And to read a list of the structure that you define yourself

Full code you can copy and paste into a refreshing console app project:

  System use; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using System.IO; // where the magic keeps using the system. time to time. Serialization. Formats. Binary; Namespace savecon {class program {static zero main (string [] args) {random rand = new random (); Byte [] data = new byte [20]; Rand.NextBytes (data); Databobz A = new databases (data); DataBuzz B = new databases (data); DataColonationDC_Old = new dataclose (); Dc_old.Add (a); Dc_old.Add (b); DataCollection.ToFile ("D: \\ data.my", dc_old); // I use D: Your different data will be dc_new = DataCollection.FromFile ("D: \\ data.my"); }} [Serializable] // magic structure dataobase {byte [] data; Public DataObs (Byte [] D) {Data = D; }} [Serializable] // more magic class DataCollection: IEnumerable & lt; DataObj & gt; {List & lt; DataObj & gt; Dataobjects; // from the list & lt; & Gt; Public Data Clipation () along with SerialJobs has been attributed (Databases = New list & lt; DataObj & gt; ();} Public Static Data Collection to File (String Path) {DataCollection dcol; (FileStream FS = File. Openeride (Path)) using {dcol = (DataCollection) new binary formatting (). Deserialize (FS); // Magic is coming) return dcol; } Public static Zero ToFile (String Path, Dataclication DC) {using (Filestream FS = File. Open (Path, File Modes Composition, File Access .Redrite)) {New BinarFormat (). Serialize (fs, dc); }} Add Public Zero (DataObject Dob) {dataobjects.Add (dobj); } / Note that there is nothing to do Ienumerable serial (saving data) public IEnumerator & lt; DataObj & gt; GetEnumerator () {return dataobjects.AsEnumerable (). GetEnumerator (); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () {return dataobjects.GetEnumerator (); }}}  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -