Wouter Vandenputte
Wouter Vandenputte

Reputation: 137

Is merely creating a FileStream object expensive?

Suppose I just have this single line

var fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);

Is this an expensive operation? Could this already be an I/O operation or not? Because I am nog reading from it by simply calling the constructor, or do I indirectly?

What I mean by expensive is just I/O wise. Does it do anything more than just being a POCO in memory?

Upvotes: 1

Views: 71

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064044

It isn't just a POCO, since it involves an OS file handle (for here). As such, it should be avoided if you aren't actually planning to access data.

Upvotes: 3

Related Questions