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.

In C# what is the difference between public static void and static void and how come void can be exchanged to a reference?

Update:

The wording wasn't right... I have seen public static Car instead of public static void, Car referring to a Car in the class I think...

1 Answer

Relevance
  • 7 years ago
    Favorite Answer

    The difference is "accessibility", which you might have seen called "visibility" in other languages.

    "public static void" has public visibility--any code can use whatever is being defined.

    "static void" has a default visibility that depends on where the definition occurs. In a class or struct, the default is "private".

    As for "void can be exchanged to a reference", I'm afraid I don't have the pleasure of understanding you. The void type can't be applied to a variable declaration, as far as I know, except in unsafe mode to declare a pointer to an unknown type. There are no objects of type void, so a reference to void is not possible.

Still have questions? Get your answers by asking now.