Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you know the file isn’t too large, there also is File.ReadAllBytes (https://docs.microsoft.com/en-us/dotnet/api/system.io.file.r...)

My C# is very rusty (no pun intended) but I would guess the core of the program could be something like

  File.ReadAllBytes("file.bin").Where(x => x == '1').Count()
And nitpick: the code you gave has a bug. file.Read can return less than 4096. If so, you should only loop over the part of the buffer it filled.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: