# Why is C C Sharp

## C # Operators and Expressions (C # Reference)

C # offers many different operators. Many of these operators are supported by the built-in types and allow you to perform basic operations on the values of these types. These operators are divided into the following groups:

Usually you can overload these operators, that is, specify the operator behavior for the operands of a user-defined type.

The simplest C # expressions are literals (for example, integers and real numbers) and names of variables. You can combine these into complex expressions using operators. Operator precedence and associativity determine the order in which operations in an expression are performed. You can use parentheses to change the order of evaluation, which is determined by operator precedence and associativity.

The following code is the example of the expressions on the right side of the assignments:

Usually an expression produces a result and can be enclosed in another expression. A method call is an example of an expression that does not produce a result. It can only be used as a statement like the following example.

Here are a few more expressions provided by C #:

Interpolated string expressions that provide convenient syntax for creating formatted strings:

Lambda expressions that you can use to create anonymous functions:

Query expressions that let you use query functions directly in C #:

You can use an expression body function to provide a precise definition for a method, constructor, property, indexer, or finalizer.

### Operator precedence

In a multi-operator expression, the higher precedence operators are evaluated before the lower precedence operators. In the following example, multiplication is done first because it has a higher precedence than addition:

Use parentheses to change the order of evaluation, which is determined by operator precedence:

The following table lists the C # operators, from highest to lowest precedence. The operators on each line have the same precedence.

Operators | Category or name |
---|---|

x.y, f (x), a [i],,, x ++, x--, x !, new, typeof, checked, unchecked, default, nameof, delegate, sizeof, stackalloc, x-> y | Primary |

+ x, -x,! x, ~ x, ++ x, --x, ^ x, (T) x, await, & x, * x, true and false | Unary |

x..y | Area |

switch | -Expression |

With | -Expression |

x * y, x / y, x% y | Multiplicative |

x + y, x - y | Additive |

x << y, x >> y | Shift |

x | Relational and type test |

x == y, x! = y | equality |

Boolean logical AND operator or bitwise logical AND operator | |

Boolean logical XOR operator or bitwise logical XOR operator | |

Boolean logical OR operator or bitwise logical OR operator | |

x && y | Conditional AND |

x || y | Conditional OR |

x ?? y | Zero composition operator |

c? t: f | Conditional operator |

x = y, x + = y, x - = y, x * = y, x / = y, x% = y, x & = y, x | = y, x ^ = y, x << = y, x >> = y, x ?? = y, => | Assignment and lambda declaration |

### Operator associativity

When operators have the same precedence, the associativity of the operators determines the order in which operations are performed:

*Left Associative*Operators are evaluated from left to right. With the exception of the assignment operators and the NULL collection operator, all binary operators are left-associative. is evaluated as, for example.*Legal associative*Operators are evaluated from right to left. The assignment operators, the NULL collection operators, and the conditional operator are right-associative. is evaluated as, for example.

Use parentheses to change the order of evaluation determined by operator associativity:

### Operand evaluation

Regardless of operator precedence and associativity, the operands in an expression are evaluated from left to right. The following examples illustrate the order in which operators and operands are evaluated:

expression | Order of evaluation |
---|---|

a, b, + | |

a, b, c, *, + | |

a, b, /, c, d, *, + | |

a, b, c, +, /, d, * |

As a rule, all operands of an operator are evaluated. However, some operators evaluate operands conditionally. That is, the value of the operand on the far left in such an operator defines whether (or which) other operands should be evaluated. These operators are the conditional logical operators AND () and OR (), the NULL collective operators and, the NULL-conditional operators and and the conditional operator. See the description of each operator for more information.

### C # language specification

For more information, see the following sections of the C # language specification:

### See also

### Is this page helpful?

- What is the secret behind pyramids
- Should I code professionally to become a hacker
- Who are some southern opera singers
- How long should a mechanical pencil last?
- How do I show toolbar buttons
- Who deserves to win Wimbledon
- Is there a relationship that cannot be saved
- Is the galaxy infinite or finite
- Why are stars called stars
- What attracts a tyrant
- What is the Quickbooks Online Customer Support Number
- Is GoLang reliable
- When will Google automatically delete your data
- Would Munir still fit into Barca
- What do you think of Hardik Pandya
- What are some examples of ecological succession
- How many gravitational waves did LIGO recognize
- What was NASA's craziest project
- Is Thailand concerned about the Zika virus
- Where can I download the iPhone X wallpaper
- What latitude is Toronto
- What is linoleum made of
- Which tissue is in blood vessels
- What do Koreans think of Hungary