static classes for C # Basic Learning (0708)

Source: Internet
Author: User

In a static class, all the members that are contained are "static members"

Not all static members must be unloaded in a static class

Static members are "classes", not specific "objects", so access to static members cannot be accessed through objects (objects. Property name), you can access static members directly through the class name.

Accessing the static member at any point in the program is actually accessing the same piece of memory, and there is a place where the value is changed, and the values obtained everywhere are changed.

The data for a static member is not freed until the program exits, and the instance object can perform garbage collection as long as it is used.

Static members in a class are initialized the first time a static class is used.

Features of static constructors:

Static constructors cannot be called manually, but are called automatically the first time a static member is used, so you cannot add an access modifier to the static constructor, which defaults to Peivate

Because a static constructor is automatically called by the system, it does not require (cannot) add any parameters

Static constructors execute only once

Executes when a static class or static member is used for the first time

Polymorphic

polymorphic role: The different sub-class objects are considered as the parent class, you can block the differences between different sub-class objects, write generic code, make a general change to adapt to the changing needs

Another way to type conversions (AS)

Type conversions are performed by as, even if the conversion fails to report an exception, but instead returns a null

Person P=new Student ();

Student s=p as Student;

if (s!=null)

{

Console.WriteLine ("Conversion succeeded!") ")

}

Else

{

Console.WriteLine ("Conversion failed! ")

}

static classes for C # Basic Learning (0708)

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.