I am new to C# from java. In java I am able to use a decorator for a File object where I can have the file instance as a member variable and add the methods with the operations I need to perform on the file. This seems to be a headache with C#.
In my class I have this:

private File myFile;

And I get this error
Cannot declare a variable of static type 'System.IO.File'

What do other c# programmers do in this case ?

Recommended Answers

All 3 Replies

C# programmers don't declare static types, they just use them: File."whatever";, just like Math.Sin(123.456);

As ddanbe said, in the case of file it is just a class with File utilities but you cannot create an instance of it. You can use the System.IO.FileStream class for more advanced I/O operations, or you can use System.IO.FileSystemWatcher to watch for modifications of a file on disk. This Between File.* methods and the two additional classes I mentioned that should handle about 99% of your file needs.

I didn't knew this (It's static) about File in C#. I got the idea.

Thank you all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.