We use cookies.This website uses essential cookies to operate core features. With your consent, we also use analytics cookies to understand traffic and improve the service. For more details, see our .
Was this tool helpful to use?
Your feedback helps us make it better
Quickly check C# operator precedence and associativity with this free online reference table.
A curated syntax reference, not a compiler or example validator. Local group numbers do not replace version-specific grammar, typing or evaluation rules. Examples keep their original code and literals. Reference
x.yPrimary ExpressionsLeft-associative访问对象的成员(字段、方法、属性等)。
obj.Namex?.yPrimary ExpressionsLeft-associative若左操作数为 null 则返回 null,否则访问其成员,避免 NullReferenceException。
obj?.Namef(x)Primary ExpressionsLeft-associative调用方法或委托。
Console.WriteLine(x)a[i]Primary ExpressionsLeft-associative访问数组、列表或索引器。
arr[0]a?[i]Primary ExpressionsLeft-associative若左操作数为 null 则返回 null,否则访问其索引。
list?[0]x++Primary ExpressionsLeft-associative返回当前值后将变量加 1。
i++x--Primary ExpressionsLeft-associative返回当前值后将变量减 1。
i--newPrimary ExpressionsRight-associative创建类型的新实例。
new List<int>()typeof(T)Primary ExpressionsNo Associativity返回类型的 System.Type 对象。
typeof(string)checkedPrimary ExpressionsNo Associativity在运算时检查算术溢出,溢出时抛出 OverflowException。
checked(a + b)uncheckedPrimary ExpressionsNo Associativity禁用算术溢出检查,允许结果回绕。
unchecked(a + b)default(T)Primary ExpressionsNo Associativity返回类型的默认值(引用类型为 null,值类型为 0 等)。
default(int)nameofPrimary ExpressionsNo Associativity在编译期返回变量、类型或成员的字符串名称,用于日志或异常。
nameof(MyClass)delegatePrimary ExpressionsLeft-associative声明匿名委托方法。
delegate(int x) { return x * 2; }sizeofPrimary ExpressionsNo Associativity返回值类型在内存中占用的字节数。
sizeof(int)->Primary ExpressionsLeft-associative在 unsafe 上下文中通过指针访问结构体成员。
p->X+xUnary OperatorsRight-associative返回操作数的值,保留符号。
+5-xUnary OperatorsRight-associative返回操作数的相反数。
-x!xUnary OperatorsRight-associative对 bool 值取反。
!isReady~xUnary OperatorsRight-associative对整数按位取反,每一位 0 变 1、1 变 0。
~0b1010++xUnary OperatorsRight-associative先将变量加 1,再返回新值。
++i--xUnary OperatorsRight-associative先将变量减 1,再返回新值。
--i(T)xUnary OperatorsRight-associative将表达式显式转换为指定类型。
(int)3.14awaitUnary OperatorsRight-associative异步等待 Task 完成并返回结果。
await GetAsync()&xUnary OperatorsRight-associative在 unsafe 上下文中获取变量的地址。
&value*xUnary OperatorsRight-associative在 unsafe 上下文中读取指针指向的值。
*ptrue / falseUnary OperatorsRight-associative由用户在类型上定义的 true/false 运算符,常用于短路逻辑。
operator true(MyType x)x..yUnary OperatorsLeft-associative构造 System.Range,用于切片,例如 arr[1..4]。
arr[1..4]switchUnary OperatorsLeft-associative基于模式匹配返回对应的值。
x switch { 1 => "a", _ => "b" }withUnary OperatorsLeft-associative复制 record 并修改部分属性。
p with { Age = 18 }*Multiplicative OperatorsLeft-associative两个操作数相乘。
a * b/Multiplicative OperatorsLeft-associative整数除法向零取整;浮点除法返回精确结果。
10 / 3%Multiplicative OperatorsLeft-associative返回两数相除的余数。
10 % 3+Additive OperatorsLeft-associative数值相加,或将字符串拼接。
"a" + "b"-Additive OperatorsLeft-associative数值相减或从委托链中移除目标。
a - b<<Shift OperatorsLeft-associative将位向左移动指定位数,低位补 0。
1 << 3>>Shift OperatorsLeft-associative将位向右移动,有符号数保留符号。
8 >> 2>>>Shift OperatorsLeft-associativeC# 11+ 提供,按位右移并在高位补 0,忽略符号位。
(-1) >>> 1<Relational & TypeLeft-associative比较两个操作数,左小于右返回 true。
a < b>Relational & TypeLeft-associative比较两个操作数,左大于右返回 true。
a > b<=Relational & TypeLeft-associative左小于或等于右返回 true。
a <= b>=Relational & TypeLeft-associative左大于或等于右返回 true。
a >= bisRelational & TypeLeft-associative测试对象是否为指定类型或匹配模式。
obj is string sasRelational & TypeLeft-associative尝试类型转换,失败时返回 null 而不是抛异常。
obj as MyType==Equality OperatorsLeft-associative判断两个值是否相等,引用类型默认比较引用,可被重载。
a == b!=Equality OperatorsLeft-associative判断两个值是否不相等,可被重载。
a != b&Bitwise & LogicalLeft-associative整数按位与,bool 上为非短路逻辑与。
a & b^Bitwise & LogicalLeft-associative整数按位异或,bool 上为逻辑异或。
a ^ b|Bitwise & LogicalLeft-associative整数按位或,bool 上为非短路逻辑或。
a | b&&Bitwise & LogicalLeft-associative短路逻辑与:左操作数为 false 时不计算右操作数。
a && b||Bitwise & LogicalLeft-associative短路逻辑或:左操作数为 true 时不计算右操作数。
a || b??Conditional OperatorRight-associative若左操作数为 null 则返回右操作数。
name ?? "匿名"?:Conditional OperatorRight-associative根据条件返回两个值之一,等价于 if-else 表达式。
x > 0 ? "正" : "负"=Assignment OperatorsRight-associative将右操作数的值赋给左操作数。
x = 10+=Assignment OperatorsRight-associativex = x + y,或为事件添加处理器。
x += 1-=Assignment OperatorsRight-associativex = x - y,或为事件移除处理器。
x -= 1*=Assignment OperatorsRight-associativex = x * y 的简写。
x *= 2/=Assignment OperatorsRight-associativex = x / y 的简写。
x /= 2%=Assignment OperatorsRight-associativex = x % y 的简写。
x %= 3&=Assignment OperatorsRight-associativex = x & y 的简写。
x &= 0xFF|=Assignment OperatorsRight-associativex = x | y 的简写。
x |= 0x01^=Assignment OperatorsRight-associativex = x ^ y 的简写。
x ^= mask<<=Assignment OperatorsRight-associativex = x << y 的简写。
x <<= 2>>=Assignment OperatorsRight-associativex = x >> y 的简写。
x >>= 2>>>=Assignment OperatorsRight-associativex = x >>> y 的简写,C# 11+ 支持。
x >>>= 1??=Assignment OperatorsRight-associative仅当左操作数为 null 时才赋值。
name ??= "匿名"=>Lambda ExpressionsRight-associative定义匿名函数或表达式体成员。
(x, y) => x + yOverview
Understand what the tool solves, how it works, and the boundaries of its data.
This page is a searchable reference for the C# operators included in its table. Use it to look up a displayed symbol, category, precedence level, or associativity while reading an expression. The results show the operator symbol, category, associativity, a short description, and a C# example. They are reference entries: the page does not parse, compile, or run an expression you enter.
Language detail: the controls and category names are in English, while the operator names and short descriptions in the current records are in Simplified Chinese. C# symbols and example code remain in their original form. Search by symbol, code example, or precedence number when an English keyword does not match a Chinese description.
Precedence tells you how operators at different levels group. For example, 2 + 3 * 4 groups as 2 + (3 * 4), because multiplication has higher precedence than addition. Associativity resolves grouping among operators at the same level: a - b - c groups as (a - b) - c. Neither rule alone describes the order in which every operand is evaluated. Microsoft’s C# reference makes that distinction and gives the current language operator list.
Guide
Follow the workflow and verify inputs and outputs with practical examples.
Enter a symbol such as ??, a code example, or a precedence number. The search checks symbols, names, descriptions, examples, and level numbers. Since record names and descriptions are Simplified Chinese, English words may not find the corresponding row.
Choose a category such as Shift Operators or Assignment Operators, then optionally choose left-associative, right-associative, or no associativity. Both filters apply together. Restore each filter to All to broaden the results.
Rows are grouped by precedence level; this reference labels level 1 as the highest and uses larger numbers for lower precedence. Compare entries at the same level to understand grouping, then add parentheses in your own code when they make intent clearer. Use the copy controls if you need a symbol or example snippet.
If no rows match, try the exact symbol, remove one filter, or restore both filters to All. A zero-result message only means the current search and filters found no matching entry.
Use cases
See how the tool fits into real work and everyday tasks.
When studying a mixed expression, look up its symbols and levels, then rewrite the expression with explicit parentheses to see how the groups relate.
During a code review, filter to logical or comparison operators and check the displayed grouping information. Use parentheses in the code when teammates could read the expression differently.
When reading unfamiliar C# code, search for an operator symbol or example to find its listed category and associativity without scanning the whole table.
Q&A
Find concise answers to common questions and confusing cases.
No. It filters a reference list; it does not accept a complete expression for parsing, compilation, or execution.
Operator names and descriptions in the current records are Simplified Chinese. Search with the operator symbol, a code example, or a precedence number, or use the English category and associativity filters.
No. Associativity describes how operators at the same precedence level group syntactically. Operand evaluation order is a separate C# rule; consult the official reference for that distinction.
Do not assume so. This is a curated static table and does not promise complete coverage of every language version or context. Check the C# language reference and your project’s language version for newer syntax or version-specific questions.
Notes
Review scope, result limitations, and important precautions before use.
This table is a quick lookup aid, not a compiler, a complete language specification, or a version selector. C# adds features over time, and some syntax depends on context, operand types, or the selected language version. If a symbol is missing or the expression affects important behavior, verify it against the official documentation for the C# version used by your project and compile it in that project. Parentheses can make intended grouping clearer, but they do not by themselves confirm that an expression is valid or behaves as intended.
Related
Discover related tools, collections, and available API capabilities.