Skip to content

Commit

Permalink
doc: update cs.md (#387)
Browse files Browse the repository at this point in the history
* doc: update cs.md

* doc: update cs.md

* doc: update cs.md
  • Loading branch information
itldg committed Jun 29, 2023
1 parent 937426b commit 0125cc1
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions docs/cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,63 @@ null | false | false | null | null | null
null | null | null | null | null | null
<!--rehype:className=show-header-->

### 算术运算符
<!--rehype:wrap-class=col-span-1-->

C# 支持下表中的所有算术运算符。假设变量 A 的值为 10,变量 B 的值为 20,则:

| 运算符 | 描述 | 实例 |
| :----- | -------------------------------- | ----------------- |
| + | 把两个操作数相加 | A + B 将得到 30 |
| - | 从第一个操作数中减去第二个操作数 | A - B 将得到 -10 |
| \* | 把两个操作数相乘 | A \* B 将得到 200 |
| / | 分子除以分母 | B / A 将得到 2 |
| % | 取模运算符,整除后的余数 | B % A 将得到 0 |
| ++ | 自增运算符,整数值增加 1 | A++ 将得到 11 |
| -- | 自减运算符,整数值减少 1 | A-- 将得到 9 |
<!--rehype:className=show-header-->

### 关系运算符
<!--rehype:wrap-class=col-span-2-->

C# 支持下表中的所有关系运算符。假设变量 A 的值为 1,变量 B 的值为 2,则:

| 运算符 | 描述 | 实例 |
| :----- | -------------------------------------------------------------- | ----------------- |
| == | 检查两个操作数的值是否相等,如果相等则条件为真。 | (A == B) 不为真。 |
| != | 检查两个操作数的值是否相等,如果不相等则条件为真。 | (A != B) 为真。 |
| > | 检查左操作数的值是否大于右操作数的值,如果是则条件为真。 | (A > B) 不为真。 |
| < | 检查左操作数的值是否小于右操作数的值,如果是则条件为真。 | (A < B) 为真。 |
| >= | 检查左操作数的值是否大于或等于右操作数的值,如果是则条件为真。 | (A >= B) 不为真。 |
| <= | 检查左操作数的值是否小于或等于右操作数的值,如果是则条件为真。 | (A <= B) 为真。 |
<!--rehype:className=show-header-->

### 运算符优先级
<!--rehype:wrap-class=col-span-3-->

运算符的优先级确定表达式中项的组合。这会影响到一个表达式如何计算。某些运算符比其他运算符有更高的优先级,例如,乘除运算符具有比加减运算符更高的优先级。

下表将按运算符优先级从高到低列出各个运算符,具有较高优先级的运算符出现在表格的上面,具有较低优先级的运算符出现在表格的下面。在表达式中,较高优先级的运算符会优先被计算。

| 类别 | 运算符 | 结合性 |
| :--------- | ---------------------------------- | -------- |
| 后缀 | () [] -> . ++ - - | 从左到右 |
| 一元 | + - ! ~ ++ - - (type)\* & sizeof | 从右到左 |
| 乘除 | \* / % | 从左到右 |
| 加减 | + - | 从左到右 |
| 移位 | << >> | 从左到右 |
| 关系 | < <= > >= | 从左到右 |
| 相等 | == != | 从左到右 |
| 位与 AND | & | 从左到右 |
| 位异或 XOR | ^ | 从左到右 |
| 位或 OR | \| | 从左到右 |
| 逻辑与 AND | && | 从左到右 |
| 逻辑或 OR | \|\| | 从左到右 |
| 条件 | ?: | 从右到左 |
| 赋值 | = += -= \*= /= %=>>= <<= &= ^= \|= | 从右到左 |
| 逗号 | , | 从左到右 |
<!--rehype:className=show-header-->

杂项
-----------

Expand Down

0 comments on commit 0125cc1

Please sign in to comment.