Runtime: BinaryReader should also accept String as path filename for contructor

Created on 7 Jul 2018  路  6Comments  路  Source: dotnet/runtime

Most helpful comment

Sounds like a good opportunity then to teach about composability. :)

All 6 comments

@scls19fr What about creating a FileStream and then passing that into the BinaryReader/BinaryWriter. Wouldn't that work? Having knowledge of file semantics in the BinaryReader/BinaryWriter classes isn't ideal - which is why they take instances of Stream.

Why creating an additional object (FileStream) when you don't really need it. If you use a BinaryReader you will necessary need a stream with read file access. That should be implicit not explicit (or we should have an implicit way of doing)

Why creating an additional object (FileStream) when you don't really need it.

Are you talking about from a performance perspective? The implementation of StreamReader/Writer when provided with a path just construct a FileStream, so those constructors don't avoid that additional object.

That should be implicit not explicit (or we should have an implicit way of doing)

We actually wanted to remove those constructors from StreamReader/Writer in .NET Core, and did in 1.x; they were only added back in .NET Core 2.0 for compatibility.

I personally don't think it's worth adding such new overloads to BinaryReader/Writer in order to be able to write:
```C#
var reader = new BinaryReader(path);

instead of:
```C#
var reader = new BinaryReader(File.OpenRead(path));

Doesn't seem like there's enough benefit there.

My problem is about teaching VB.Net... not about performance issue.

It's a beginer course with very few time to spend... so the simpler it's, the better it is.

Sounds like a good opportunity then to teach about composability. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jzabroski picture jzabroski  路  3Comments

omariom picture omariom  路  3Comments

v0l picture v0l  路  3Comments

btecu picture btecu  路  3Comments

chunseoklee picture chunseoklee  路  3Comments