locked
Static Class in C# RRS feed

  • Question

  • User1873565496 posted

    what is the use of static class ?

    when we will use this static class?

    Tuesday, August 12, 2008 8:58 AM

Answers

  • User-837620913 posted

    From the documentation:

    A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself. For example, if you have a static class that is named UtilityClass that has a public method named MethodA, you call the method as shown in the following example:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 12, 2008 9:00 AM
  • User599164775 posted

    Static class is special class in which all the variables and methods are static, the use of static class is... there is not any dependancy to each other methods or varibleas, then can leave entirly alone... the best way to use static class is to put all the common function or code at the same place, which does not need to intract with each other, also they dont use much memory space as they always in single mode.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 12, 2008 9:24 AM

All replies

  • User-837620913 posted

    From the documentation:

    A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself. For example, if you have a static class that is named UtilityClass that has a public method named MethodA, you call the method as shown in the following example:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 12, 2008 9:00 AM
  • User599164775 posted

    Static class is special class in which all the variables and methods are static, the use of static class is... there is not any dependancy to each other methods or varibleas, then can leave entirly alone... the best way to use static class is to put all the common function or code at the same place, which does not need to intract with each other, also they dont use much memory space as they always in single mode.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 12, 2008 9:24 AM