C # class access modifier,

Source: Internet
Author: User

C # class access modifier,

By default, the class is declared as internal, that is, only the code in the current project can access it. You can use the internal access modifier keyword to explicitly specify, but this is not necessary. Classes of this type are defined by default. However, the default access level of the C # method is private.

The access level of method or attribute modifier is as follows:

Access Modifier

Yi

Public

Access is unrestricted and can be accessed by code inside and outside the class

Protected

Accessible domains are limited to or derived from the class.

Internal

The accessible domain is limited to the Assembly where the class is located.

Protected internal

Protected or internal, you can access a field that is limited to the program where the class is located or the class that is derived from it.

Private

The accessible domain is limited to the class to which it belongs.

Access modifier combinations that can be used in class definitions

None or internal class can only be accessed in the current project
Public class can be accessed anywhere
Abstract or internal abstract class can only be accessed in the current project, cannot be instantiated, can only inherit
The public abstract class can be accessed anywhere. It cannot be instantiated and can only be inherited.
The sealed or internal sealed class can only be accessed in the current project. It cannot be derived and can only be instantiated.
The public sealed class can be accessed anywhere. It cannot be derived and can only be instantiated.

 

The following describes the default access modifiers for methods and classes in C #.

Interface)

The default access modifier for interface members is public, and the access modifier cannot be displayed.

 

Class)

The default constructor is a public access modifier.

The Destructor cannot display the access modifier and is a private access modifier by default.

The default access modifier for class members is private;

 

Enumeration (enum)

By default, enumeration type members are public access modifiers and cannot be displayed with modifiers.

 

Structure (struct)

The structure member is a private Modifier by default.

The structure member cannot be declared as a protected member because the structure does not support inheritance.

 

Nested type

The default access modifier of the nested type is private. It is consistent with the default access type of the class and structure members.


C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

Related Article

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.