Recommended Posts

C# gurus,
In C++, we have this function to check if a file is currently open:
fstream::is_open()
What is the C# equivalent?
p.s. Anyone notice gamedev.net has been very slow lately, takes my browser 30 sec to load a page each time!?

0

Share this post

Link to post

Share on other sites

Take a look at the System.IO namespace. You'll see that if a file fails to open the constructor throws an exception. Therefore, if no exception has been thrown then the file has been successfully opened. No need for an is_open function.

Share this post

Link to post

Share on other sites

The only way is to see if the object has been created as a valid object, which implies the file is open and ready for access. So, initialise the file object to null and use a test for null to determine if the file is open. null is a valid c# keyword.