0

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 ?

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by mansour77
0

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

0

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.

0

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

Thank you all.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.