I need ot read a binary file. But getting error. How can i do it ?
Im trying to explain what else can i write ?
using System;
using System.IO;
using System.Net;
using System.Text;
namespace BinaryReader
{
public partial class Form1 : Form1
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void R()
{
using (BinaryReader br = new BinaryReader(File.Open("file.bin", FileMode.Open)))
{
// 2.
// Position and length variables.
int pos = 0;
// 2A.
// Use BaseStream.
int length = (int)b.BaseStream.Length;
while (pos < length)
{
// 3.
// Read integer.
int v = b.ReadInt32();
Console.WriteLine(v);
// 4.
// Advance our position variable.
pos += sizeof(int);
}
}
}
}
}
On this line im getting error:
using (BinaryReader br = new BinaryReader(File.Open("file.bin", FileMode.Open)))
Error ‘BinaryReader’ is a ‘namespace’ but is used like a ‘type’
How can i fix it ?
You have a name collision with your own namespace. Rename it, for example, to
BinaryReaderTest, or use full name ofSystem.IO.BinaryReaderfor theSystem.IO‘sBinaryReaderclass: