Value types and reference type operators with case statements and jump statements

Source: Internet
Author: User
Tags bitwise operators

First summarize the value types and reference types

Teacher's most classic sentence: The value type of the variable and the value is one of the reference types of variables and values are separate.

The variables and values of the value type are the variables in the thread stack that produce the reference type in the thread stack, and the value is a referential relationship in the managed heap where the variable and the value are!!!!!! 1

Look at the following code

 Static voidMain (string[] args) {            //value-type variables and values are one            inti =0; Doublex =1.23; //reference-type variables and values are separateStudent Student1 =NewStudent (); Student1. Name="Xiao Ming"; Student Student2=Student1; Console.WriteLine ("{0}\t{1}", Student1. Name, Student2.            Name); //a little bit of a C-language pointer.Student2. Name ="Xiao Wang"; Console.WriteLine ("{0}\t{1}", Student1. Name, Student2.            Name);        Console.readkey (); }

Operation Result:

To summarize:

Value type: Integer floating-point Boolean character type

Reference types: All classes, interfaces, and delegate strings (more special) arrays of array collections ...

Then briefly summarize the unary operator.

Unary operators are mostly + +,--。

However, the order in which operators are placed in the variable position

I++ is the first to take the value I again +1;

++i is I first carries on +1 again to take the value;

The code is as follows:

int 0 ;            Console.WriteLine (i+ +); // the output is 0            . Console.WriteLine (++i); // the output is 2 .

Binary operators: +-*/%

Just note/:/The result of the operation is the same as the highest bit precision (type)!!!!

Ternary operator:? :

This is primarily used for judging and then assigning a value similar to the if else effect, but it's quite simple.

The code is as follows:

// two-digit maximum value            int  A ;             int 1 ;             int result=x>y?x:y; // satisfies the condition to take the first value does not satisfy the condition takes the second value            Console.WriteLine (Result); // output result =12            Console.readkey ();

Assignment operator: + = = .....

Relational operators:> < = = >= <=! =

Logical operators:

! Non-operational

& or && and arithmetic

|  or | | or arithmetic

Here to explain & and && | | The difference:

A&b A and B are calculated a&&b a evaluates to False and B is not computed.

a| b A and B have to calculate a| | b A evaluates to True does not calculate B

This shows && | | more efficient and reasonable.

Bitwise operators:

>> Right Shift

<< left Shift

& and

| Or

~ different

^ XOR or

All bitwise operations are the conversion of numeric values to binary operations.

The code and details are as follows:

intA = A;//Binary code: 1100            intb =5;//Binary code: 0101//The same number of digits is 1 for the operation and 1 for the remainder is 0.//results: 1000-digit =4            intc = A & B;//result is 4//or arithmetic the same number of digits as long as one or two is 1 and the other is 1 0//Results: 1101            intD = A | b//The result is//non-operation 0 take 1 1 take 0 only for one number//results: 0011            inte = ~a;//result is 3//XOR operation the same number of digits is 1 different is 0//The result is 0110            intF=a^b;//result is 5//the left-shift operation here moves a two .//results: 110000            intg=a<<2;//The result is that 48 is actually the time to move the number of a by 2//right-shift operation here, move a two .//results: 0011            inth = a >>2;//The result is that 3 is actually the second of the number of moves that divide a by 2

Here is the jump statement

Keyword goto

The code is as follows

Static int  Main (string[] args)        {            int6;             if 0 Goto large;             =-x;         return x;        }

If x>0 is satisfied, jump directly to the statement following the large (label)

Generally do not advocate this but in special cases: in the deep loop, break can only jump out to the previous layer, you must use the jump statement to completely jump out of the loop.

Here is the switch and case

It's very simple. Here's the main explanation for the break and the use of the Swich is to judge that the exit is dependent on break if there is no break behind a case, the execution continues until the break appears.

Specific should be based on the actual situation to use if there are multiple situations are using a treatment method can not be added to every sentence break.

Look at the following code:

///output the number of days per month for one year            //Enter Year:            intNyear =int.            Parse (Console.ReadLine ());  for(intI=1;i< -; i++)            {                Switch(i) { Case 1:                     Case 3:                     Case 5:                     Case 7:                     Case 8:                     Case Ten:                     Case  A: Console.WriteLine ("{0} month has 31 days", i);  Break;  Case 4:                     Case 6:                     Case 9:                     Case  One: Console.WriteLine ("{0} month has 30 days", i);  Break;  Case 2:                        if(((nyear%4==0) && (nyear% -!=0))|| nyear% -==0) Console.WriteLine ("February has 29 days"); ElseConsole.WriteLine ("February 28 Days");  Break; }              }

This makes it easier and quicker to notice the statement about leap year judgments with > or

  

Value types and reference type operators with case statements and jump statements

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.