C# BinaryReaderLast Updated : 19 Jan 2026 In the C# programming language, a BinaryReader is a class that is used to read binary data from a stream. It is found in the System.IO namespace. It also supports reading a string in a specific encoding. The BinaryReader class belongs to the System.IO namespace, and it is used to read primitive data types. The BinaryReader uses the UTF-8 encoding, which helps to read the data until we define another character encoding during the creation of its object. ![]() Syntax:It has the following syntax. Or with encoding: In this syntax,
Simple C# BinaryReader Class ExampleLet us take an example to illustrate the BinaryReader class in C#. ExampleCompile and RunOutput: The integer value is 555 The double value is 45.67 The string value is Hello, Welcome to Tpoint tech Explanation: In this example, we demonstrate the use of the BinaryReader classes in C#. First, we create a binary file named example.bin, which writes three types of data: integer, double, and string. After that, we use the BinaryReader class to read the data from the file. At last, we are using the Console.WriteLine() method to print the read data. Methods of the BinaryReader Class in C#In C#, the BinaryReader Class has several functions, which are as follows.
C# Example to Read and Write Multiple Data Types Using BinaryReader and BinaryWriterLet us take an example to define the methods of the BinaryReader class in C#. ExampleCompile and RunOutput: The integer value is 125 The double value is 35.75 The boolean value is True The character value is M The string value is Hello, Welcome to Tpoint Tech Explanation: In this example, we create a file named ex.bin using BinaryWriter. The BinaryWriter class converts each value into its binary representation. The BinaryReader class reads the same file and retrieves the data in the same order. After that, we use the Console.WriteLine() method to print the retrieved values. C# BinaryReader() Function Example with ReadString() MethodLet us take an example to illustrate the ReadString() method in the BinaryReader class in C#. ExampleCompile and RunOutput: Message: Welcome to Tpoint Tech Explanation: In the example, we have taken a class named Tpoint. In the main() method, we have created a binary file named exp.bin using the Binary class. After that, we use the BinaryReader class to read the same string from the file, and use the Console.WriteLine() function to display the result. Features of the BinaryReader Method in C#Several features of the BinaryReader Method in C# sare as follows:
ConclusionIn conclusion, a BinaryReader is a class that is used to read binary information from a stream. It also supports readinsg a string in a specific encoding. It provides several methods to read primitive data types, including integers, doubles, booleans, strings, and many others. It helps to read the code easily and safely from different sources. Next TopicC# StringWriter |
We request you to subscribe our newsletter for upcoming updates.