using System.IO; using System.Text; // Open a binary file for reading using (BinaryReader reader = new BinaryReader(File.Open("data.bin", FileMode.Open))) { // Read a null-terminated string from the file string str = reader.ReadNullTerminatedString(); // Display the string value Console.WriteLine("String Value: " + str); }
using System.IO; using System.Text; // Open a binary file for reading using (BinaryReader reader = new BinaryReader(File.Open("data.bin", FileMode.Open))) { // Read multiple null-terminated strings from the file while (reader.PeekChar() != -1) { string str = reader.ReadNullTerminatedString(); // Display the string value Console.WriteLine("String Value: " + str); } }These examples demonstrate the usage of ReadNullTerminatedString() method in reading null-terminated strings from a binary file. This method is available in the System.IO namespace and is part of the .NET Framework package library.