Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

i am unable to initialize a static class and run it?

some time, i want to use a static classes in csharp, for example, File class in System,IO, that is static, but i cannot have File.someMethod(),....,what is the problem

thanks

1 Answer

Relevance
  • 10 years ago
    Favorite Answer

    Static classes cannot be instantiated because they are static classes. For instance, with the File class, you use the name of the class as if it were a variable. Something like this:

    FileStream fs = File.Open("path/to/myfile.ext", FileMode.Open);

    You would then perform actions using fs instead of the File class.

    Hope this helps.

    Source(s): Software Engineer
Still have questions? Get your answers by asking now.