Cisco CloudCenter: Get the Hybrid IT Advantage


Definition - What does Precedence mean?

Precedence, in C#, is the rule that specifies the order in which certain operations need to be performed in an expression. For a given expression containing more than two operators, it determines which operations should be calculated first.

While the evaluation of an expression that is performed by humans starts from on the left and works toward the right, a C# expression is evaluated through operator precedence. Precedence helps to describe an expression that contains different kinds of operators without parentheses as an expression with parentheses by applying the predefined rules set by the C# Language Specification (CLS).

A C# expression is a sequence of one or more operands that are combined using operators and can also contain literal values, a method invocation, variables, etc. This type of expression can be evaluated as a single value, object or method. Precedence plays a vital role in determining the order in which an expression has to be evaluated.

Techopedia explains Precedence

The precedence of C# operators is similar to that used in algebraic formulas. The list of categories of C# operators with the order of precedence includes:

  • Primary ( x.y, f(x), a[x], x++, x--, new, typeof, checked, unchecked)
  • Unary (+, -, !, ~, ++x, --x, (T)x)
  • Multiplicative (*, /, %)
  • Additive (+, -)
  • Shift (<<. >>)
  • Relational and type testing (<. >, <=, >=, is, as)
  • Equality (==,!= )
  • Logical AND (&)
  • Logical XOR (^)
  • Logical OR (|)
  • Conditional AND (&&)
  • Conditional OR ||
  • Null coalescing (??)
  • Ternary (or Conditional) (?:)
  • Assignment (=, *=, /=, %=. +=, -=, , &=, ^=, |=0)

For example, the expression "a - b/c, b/c" will be evaluated first and then the quotient will be subtracted from "a" because division has a higher precedence than subtraction.

By using parentheses for the expression that needs to be evaluated first, precedence can be overridden.

This definition was written in the context of C#
Share this:

Connect with us

Email Newsletter

Join thousands of others with our weekly newsletter

The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.