码迷,mamicode.com
首页 > 其他好文 > 详细

Operators

时间:2014-10-22 21:55:03      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   for   strong   sp   div   

// -Operators can be roughly classified into three categories:
// -Unary — Act on single operands
// -Binary — Act on two operands
// -Ternary — Act on three operands

 

Mathematical Operators

// Simple Mathematical Operators
// OPERATOR CATEGORY EXAMPLE EXPRESSION    RESULT
//    +     Binary   var1 = var2 + var3;   var1 is assigned the value that is the sum of var2 and var3.
//    -     Binary   var1 = var2 - var3;   var1 is assigned the value that is the value of var3 subtracted from the value of var2.
//    *     Binary   var1 = var2 * var3;   var1 is assigned the value that is the product of var2 and var3.
//    /     Binary   var1 = var2 / var3;   var1 is assigned the value that is the result of dividing var2 by var3.
//    %     Binary   var1 = var2 % var3;   var1 is assigned the value that is the remainder when var2 is divided by var3.
//    +     Unary    var1 = +var2;         var1 is assigned the value of var2.
//    -     Unary    var1 = -var2;         var1 is assigned the value of var2 multiplied by -1.
//
//
// Increment and Decrement Operators
// OPERATOR CATEGORY EXAMPLE EXPRESSION RESULT
//   ++     Unary    var1 = ++var2;     var1 is assigned the value of var2 + 1. var2 is incremented by 1.
//   --     Unary    var1 = --var2;     var1 is assigned the value of var2 - 1. var2 is decremented by 1.
//   ++     Unary    var1 = var2++;     var1 is assigned the value of var2. var2 is incremented by 1.
//   --     Unary    var1 = var2--;     var1 is assigned the value of var2. var2 is decremented by 1.
//
//
// ++ always results in its operand being incremented by one.
// −− always results in its operand being decremented by one.
//
// Placing one of these operators before its operand means that
// the operand is affected before any other computation takes place. Placing it after the operand means that the
// operand is affected after all other computation of the expression is completed.

 1 class MainClass
 2 {
 3     static void Main()
 4     {
 5         double x;
 6         x = 1.5;
 7         Console.WriteLine(++x);
 8         x = 1.5;
 9         Console.WriteLine(x++);
10         Console.WriteLine(x);
11     }
12 }
13 
14 Output
15 2.5
16 1.5
17 2.5

 

Assignment Operators

 

// Like =, they all result in a value being assigned to the variable on their left side based on the operands and operators on their right side.
//
// OPERATOR CATEGORY EXAMPLE EXPRESSION RESULT
//   =      Binary   var1 = var2;       var1 is assigned the value of var2.
//   +=     Binary   var1 += var2;      var1 is assigned the value that is the sum of var1 and var2.
//   -=     Binary   var1 -= var2;      var1 is assigned the value that is the value of var2 subtracted from the value of var1.
//   *=     Binary   var1 *= var2;      var1 is assigned the value that is the product of var1 and var2.
//   /=     Binary   var1 /= var2;      var1 is assigned the value that is the result of dividing var1 by var2.
//   %=     Binary   var1 %= var2;      var1 is assigned the value that is the remainder when var1 is divided by var2.

 

Operator Precedence

 

// PRECEDENCE     OPERATORS
// Highest        ++, -- (used as prefi xes); +, - (unary)
//                 *, /, %
//                 +, -
//                 =, *=, /=, %=, +=, -=
// Lowest         ++, -- (used as suffixes)

 

Operators

标签:style   blog   color   io   ar   for   strong   sp   div   

原文地址:http://www.cnblogs.com/yoghourt/p/4044217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!