. NET base 3--operator

Source: Internet
Author: User
Tags arithmetic operators

(3) Convert type conversion

1. If the type is compatible with two variables, you can use an automatic type conversion or display type conversion.

However, if the two types of variables are incompatible, this can be done using a conversion factory called convert.

Note: Using convert for type conversions also requires that a condition be met:

Must go over on the surface.

1            strings ="123";2             //Convert a string to an int or double type3             DoubleD=convert.todouble (s);4             intn =Convert.ToInt32 (s);5 6 Console.WriteLine (d);7 Console.WriteLine (n);8Console.readkey ();

(4) Gaga minus minus

2. Arithmetic operators

+ +: Front + + (first +1, then participate in the operation), after + + (first take the original value operation, then itself +1)

 1  int  num = 10  ;  2  int  result = 10  + num++;         3  Console.WriteLine (num); // 11      4  Console.WriteLine (Result); // 20  5  console.readkey (); 
1             int Ten ; 2             int  + (+ +num); 3             Console.WriteLine (num);   //  One 4             //  + 5             Console.readkey ();

--: Before--, after--(IBID.)

 1  int  num = 10  ;  2  int  result = 10  + num--;  3  Console.WriteLine (num); // 9  4  Console.WriteLine (Result); // 20  5  console.readkey (); 
1             int Ten ; 2             int Ten +--num; 3             // 9 4             Console.WriteLine (result); //  + 5             Console.readkey ();

3. For operations like Gaga or subtraction that require only one operand to complete, we call it unary operators.

+-*/% for these operations that require two or more operands to complete, we call the two-dollar operator.

Unary operators have precedence over the two-tuple operator.

If you have a unary operator and a two-tuple operator in an expression, we first calculate the unary operator.

1             intA =5;2             intb = a++ + ++a *2+--a + a++;3             //5 (6) + 7*2 + 6 + 6 (7)4             //=315Console.WriteLine (a);//76Console.WriteLine (b);// to7Console.readkey ();

(5) Relational operators and logical operators

4. Relational operators

>

<

>=

<=

==

!=

A relational operator is used to describe the relationship between two things. An expression that is connected by a relational operator is called a relational expression.

5. Type bool

In C # We use the bool type to describe the right or wrong.

The bool type has only two values: a true one false

1             BOOL  the 1 ; 2             Console.WriteLine (b);    //t rue; 3             Console.readkey ();

6. Logical operators

&& Logic and

|| Logical OR

! Logical non-

An expression that is connected by a logical operator is called a logical expression.

Logical operators are generally placed on either side of a relational expression or a value of type bool.

5>3&&true

3>5| | False

The result of the logical expression is also the bool type.

1             //Let the user enter the old Soviet language and math results, output the correct judgment, correct output true, error output false. 2             //1) Lao Su's Chinese and maths scores are more than 90 points. 3             DoubleChina =convert.todouble (Console. ReadLine ());4             DoubleMath =convert.todouble (Console.ReadLine ());5             //bool B = china > && math > +;6             //Console.WriteLine (b); 7             //Console.readkey ();8             //2) Lao Su's language and mathematics have one is greater than 90 points. 9             BOOLb = China > -|| Math > -;Ten Console.WriteLine (b); OneConsole.readkey ();

7. Compound assignment operator

+=

-=

*=

/=

%=

(6) Judging leap year exercises

1Console.WriteLine ("Please enter the year to judge:");2             intYear =Convert.ToInt32 (Console.ReadLine ());3             //year can be divisible by 4004             //The year can be divisible by 4, but not divisible by 100 .5 6             //logic and precedence are higher than logical or precedence7             BOOLb = Year% -==0|| (Year%4==0&& Year% -!=0);8 Console.WriteLine (b);9Console.readkey ();

(7) If structure

Sequential structure: The program enters from the main function, from the top to the next line of execution, without dropping any line.

Branching structure: if If-else

Select structure: If Else-if switch-case

Loop structure: While do-while for foreach

1   /*2 If statement:3 Syntax:4 if (judging condition)5             {6 the code to execute;7             }8 criteria: Typically a relationship expression or a value of type bool. 9             */Ten  One  A             //Programming Implementation: If the time to kneel on the keyboard is greater than 60 minutes, then the daughter-in-law reward me for dinner -Console.WriteLine ("Please enter the time of your kneeling keyboard:"); -             intMM =Convert.ToInt32 (Console.ReadLine ()); the             if(mm> -) -             { -Console.WriteLine ("I don't have to cook dinner! "); -             } +Console.readkey ();

. NET base 3--operator

Related Article

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.