Learning programming also has a big six months, think of the teacher said the day before yesterday: "You write code are pediatrics", suddenly have snack plug ... Think about it, it's impossible to write a for loop or a foreach loop to get a high salary? I also think that is not possible, I would like to give you a brief introduction of a more advanced application.
I. indexers : When you include arrays and collection members in a class, using indexers greatly simplifies access to arrays and collection members.
Here's the syntax:
1 [modifier] datatype this [index type index ]2{3 Get {}// Get Property Code 4 set{}// Set Property Code 5 }
Modifiers include:public,protected,private,internal,new,virtual,sealed,override, Abstract,extern
Let me show you how to use:
1. First create a class, inside the class defines a length of 2 array, in the definition indexer, defined as follows.
2. In the main method, add a string that directly CW out the index of the string you want to print (you can also use loops to step through it).
3. The following is the result of the operation:
Two. Overloading of Operators : C # Allows user-defined types to overload operators by defining static member functions through the operator keyword.
1. Define the syntax for a "+" operator Overload:
1 Public Static int operator +(person P1,person P2)2{3 return p1+p2// Object name attributes are added ; 4 }
The other operators are roughly the same as those defined above.
Let me give you a brief introduction of his use:
1. First create a class, define two properties within the class, a name, an age property, as follows:
2. Called in the Main method, add the following:
3. Running Results
Because in the person class, the addition overload return is the sum of the age attributes of P1 and P2, two age is 20, and all the sum is 40.
C # Advanced Apps