Home > Backend Development > C#.Net Tutorial > How to use C# BinaryReader class?

How to use C# BinaryReader class?

PHPz
Release: 2023-09-10 18:53:02
forward
928 people have browsed it

如何使用C# BinaryReader类?

If you want to read binary information from a stream, use the BinaryReader class.

The BinaryReader class is located in the System.IO namespace.

The following shows using the BinaryReader class to read from a file -

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

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

The above method is called in the Main() method -

static void Main(string[] args) {
   WriteMe();
   ReadMe();
   Console.ReadKey();
}
Copy after login

The above is the detailed content of How to use C# BinaryReader 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