Question:

Static Classes

by Guest3523  |  12 years, 8 month(s) ago

0 LIKES UnLike

Static Classes

 Tags: classes, static

   Report

1 ANSWERS

  1. GiGi
    A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.

    Use a static class to contain methods that are not associated with a particular object. For example, it is a common requirement to create a set of methods that do not act on instance data and are not associated to a specific object in your code. You could use a static class to hold those methods.

    The main features of a static class are:

    They only contain static members.

    They cannot be instantiated.

    They are sealed.

    They cannot contain Instance Constructors.

    Creating a static class is therefore much the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.

    The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.

    Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.

Sign In or Sign Up now to answser this question!
You're reading: Static Classes

Question Stats

Latest activity: 15 years, 2 month(s) ago.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.