Do
not look back, do not, do this two points, life will be a lot easier--aaronyang blog (www.ayjs.net)-www.8mi.me
1. Operator, what else can you learn?
1.1 Unsafe operators: sizeof (. NET framework1.0 and 1.1), *,-, &
1.2 Checked and unchecked operators: Overflow exception control operator
A byte type can only be 0-255, and exceeding will result in overflow. Perform overflow check with checked, prohibit overflow check with unchecked.
1.3 Type information operator: sizeof (can determine the length (in bytes) required for a value type in the stack) is as typeof
1.4 Development rarely used << left displacement >> right displacement, same <<= and >>= equivalent to X=x>>y
1.5 Just a little more development time, you'll see int? X=1 many similar to this form of code, the tag value type is nullable type, the same is also?? operator, I told you earlier.
Priority of the 1.6 operator ... I can only rely on the feeling, also does not have much meaning, the type conversion everybody will
1.7 Comparisons, and referenceequals () reference address comparisons
1.8 Operator Overloading
Operators can be overloaded with operators (such as +-*%/, etc.) on their own defined classes or structs
① definition of MyPoint (two double)
Public structMyPoint {Private Doublex, y; PublicMyPoint (DoubleXDoubley) { This. x =x; This. y =y; } Public Override stringToString () {return "("+ This. x+","+ This. y+")"; } }
② Define multiplication * Action: Format: public static return value operator operator (parameter)
Public Static operator *(MyPoint one, mypoint) {returnnew mypoint (one.x * two.x, One.y *< c10> two.y); }
Effect:
You can also define other operations, some of which are special and must be overloaded with pairs, such as = = and! = > and < >= and <=
1.9 Types of implicit and display conversion overloads
To be blunt, defining implicit and explicit conversions between types is less common and better known. For example format:
Implicit conversion public static implicit operator float (myfloat value), use case: float a=value;
Show convert public static explicit operator myfloat (float value), use case: Myfloat a= (myfloat) value;
This is not limited to the types within the system, such as float, you can also use the other.
[Aaronyang] C # People love to learn not to learn [6]