[Aaronyang] C # People love to learn not to learn [6]

Source: Internet
Author: User

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]

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.