C # Learning Series-use of this,
If any error occurs, please correct it.
1. indicates the current class. In the current class, you can use this to access the member variables and methods of the current class. Note that this cannot be used in static methods. this can also be used for parameter passing, pass the reference of the current object.
Below is the code:
Class Program {static void Main (string [] args) {thisClass testObj = new thisClass (); Console. readLine () ;}} class thisClass {private string A {get; set;} public thisClass () {/* The static method of attribute A in the current class this category cannot access attribute A */this. A = "Test String"; Console. writeLine (this. testFun ("TestFun:");} private string TestFun (string args) {return args + this. A ;}}
2. Declare the Indexer
Indexer: Allows instances of classes and structures to be indexed in the same way as arrays. The indexer is similar to an attribute. The difference is that their accessors use parameters, which are called parameter attributes, indexes can be overloaded and belong to instance members and cannot be declared as static.
Below is the code:
Class Program {static void Main (string [] args) {indexClass intIndexClass = new indexClass (); intIndexClass [0] = new thisClass ("intIndexClass 111 "); intIndexClass [1] = new thisClass ("intIndexClass 222"); indexClass stringIndexClass = new indexClass (); stringIndexClass ["string1"] = new thisClass ("stringIndexClass string1 "); stringIndexClass ["string2"] = new thisClass ("stringIndexClass string2"); Console. readLine () ;}} class indexClass {/* declare attributes */private thisClass [] thisClassArr = new thisClass [10]; private Hashtable thisClassStrArr = new Hashtable (); /* index 1 can be reloaded and belongs to instance members. It cannot be declared as static */public thisClass this [int index] {get {return thisClassArr [index];} set {this. thisClassArr [index] = value ;}/ * Create indexer 2 */public thisClass this [string index] {get {return thisClassStrArr [index] as thisClass;} set {this. thisClassStrArr [index] = value ;}} class thisClass {private string A {get; set;} public thisClass (string str) {/* The static method of attribute A in the current class this category cannot access attribute A */this. A = str; Console. writeLine (this. testFun ("TestFun:");} private string TestFun (string args) {return args + this. A ;}}
It seems that I have read so much. Is there anything else to add?
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].