Home > Backend Development > C#.Net Tutorial > How to use C#'s BinaryWriter class?

How to use C#'s BinaryWriter class?

王林
Release: 2023-08-24 14:17:05
forward
1355 people have browsed it

How to use C#s BinaryWriter class?

If you want to write binary information to a stream, use the BinaryWriter class in C#. You can find it under the System.IO namespace.

The following is the implementation of the BinaryWriter class:

static void WriteMe() {
   using (BinaryWriter w = new BinaryWriter(File.Open("C:\abc.txt", FileMode.Create))) {
      w.Write(37.8);
      w.Write("test”);
   }
}

static void ReadMe() {
   using (BinaryReader r = new BinaryReader(File.Open("C:\abc.txt", FileMode.Open))) {
      Console.WriteLine("Value : " + r.ReadDouble());
      Console.WriteLine("Value : " + r.ReadString());
   }
}
Copy after login

Above, theBinaryWriter class opens a file and writes the content into it −

static void WriteMe() {
   using (BinaryWriter w = new BinaryWriter(File.Open("C:\abc.txt", FileMode.Create))) {

      w.Write(37.8);
      w.Write("test");
   }
}
Copy after login

The above is the detailed content of How to use C#'s BinaryWriter class?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template