C # static class static and non-static methods comparison

Source: Internet
Author: User

Static class:

Adding a static decoration to the class (classes) indicates that the class cannot be instantiated, and that a variable or function cannot be instantiated in that class.

Then if you want to add functions, variables, and properties to this static class, you must be static.

Key features of static classes:

1: Contains only static members.

2: Cannot instantiate.

3: The nature of the static class is an abstract sealed class, so it cannot be inherited, nor can it be instantiated.

4: Cannot contain instance constructors.

5: If all the members under a class need to be shared, then the class can be defined as a static class.

If your method or object is static, which means that static is a global variable, the direct class name + method name is referenced

static void Main (string[] args)        {           a.fun ();        }  public static class A   {public       static void Fun ()          {                   }    }

  

C # static class static and non-static methods comparison

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.