Reading files in C #, differences in methods

Studying C #, my books show me classes for readin files. I found 2 that are very similar, and the Visual Studio debugger does not show an obvious difference between the two.

code:

FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);


FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read);

Now I wonder what the difference is between these two ways of reading a file. Is there any inner difference you know about?

+3
source share
2 answers

The latter is just a factory that returns an instance FileStream. That is, they do the same.

Here's the implementation for Open():

public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share) {

   return new FileStream(path, mode, access, share);

}
+11
source

If you read the documentation you will find that they are the same.

+3
source

All Articles