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 .
If this tool helped you, you can buy us a coffee ☕
Quickly check C# operator precedence and associativity with this free online reference table.
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 + yWhen writing C# code, mixing multiple operators often leads to logic errors due to precedence confusion. This tool provides a complete C# operator precedence table, clearly listing precedence and associativity from highest to lowest. It helps developers quickly verify the evaluation order of expressions and avoid bugs caused by default sequencing.
This reference table is based on the C# language specification. Precedence rules in other languages (such as C++ or Java) may differ slightly, so do not mix them up. The precedence of user-defined overloaded operators remains the same as the original operators. When writing complex expressions, even after consulting this table, it is highly recommended to use parentheses to explicitly specify the evaluation order to improve code readability and maintainability.
Use this table as a quick reference when writing complex logical expressions. Typical scenario: The actual evaluation order for the expression a + b * c > d && e || f is: first multiplication b*c, then addition a+product, then comparison >, followed by logical AND &&, and finally logical OR ||. It is recommended to rewrite this as ((a + b * c) > d) && e || f, using parentheses to clarify your intent. When in doubt, prioritize adding parentheses—it is always safer than relying on default precedence.

JSON Formatter
Process JSON data online: format, minify, and validate to boost your development and debugging efficiency.
C# Code Formatter
Free online C# code formatter and beautifier. Instantly standardize indentation, fix layout issues, and improve your code's readability.

URL to JSON Parser
Parse URL strings into structured JSON to quickly extract key information like protocols, parameters, and paths.

JSON to C# Class Converter
Automatically convert JSON data into C# class definitions, ideal for .NET developers building data models.

JSON Formatter
Process JSON data online: format, minify, and validate to boost your development and debugging efficiency.
C# Code Formatter
Free online C# code formatter and beautifier. Instantly standardize indentation, fix layout issues, and improve your code's readability.

URL to JSON Parser
Parse URL strings into structured JSON to quickly extract key information like protocols, parameters, and paths.

JSON to C# Class Converter
Automatically convert JSON data into C# class definitions, ideal for .NET developers building data models.

PYC Decompiler
Restore Python bytecode .pyc files into readable source code for easy code auditing and learning. Supports mainstream versions.