- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the operator precedence in C#?
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
Operator precedence determines the grouping of terms in an expression. This affects evaluation of an expression. Certain operators have higher precedence than others do; for example, the multiplication operator has higher precedence than the addition operator.
The following is an example showing operator precedence −
Example
using System; namespace OperatorsAppl { class Program { static void Main(string[] args) { int a = 20; int b = 10; int c = 15; int d = 5; int e; e = (a + b) * c / d; // ( 30 * 15 ) / 5 Console.WriteLine("Value of (a + b) * c / d is : {0}", e); e = ((a + b) * c) / d; // (30 * 15 ) / 5 Console.WriteLine("Value of ((a + b) * c) / d is : {0}", e); e = (a + b) * (c / d); // (30) * (15/5) {0}", e); e = a + (b * c) / d; // 20 + (150/5) {0}", e); Console.ReadLine(); } } }
Output
Value of (a + b) * c / d is : 90 Value of ((a + b) * c) / d is : 90
Advertisements