SlideShare une entreprise Scribd logo
1  sur  16
Operators
Anoop K. C.
anoop@baabte.com
www.facebook.com/anoopb
aabte
twitter.com/anoop_baabte
in.linkedin.com/in/anoopbaa
bte/
+91 9746854752
In C#, an operator is a program element that is applied to one or more operands in
an expression or statement.
Operators that take one operand, such as the increment operator (++)
or new, are referred to as unary operators.
Operators that take two operands, such as arithmetic operators (+,-
,*,/), are referred to as binary operators.
One operator, the conditional operator (?:), takes three operands and is the
sole ternary operator in C#.
C# Operators - Classification
Assignment operator - =
Arithmetic operators - +, -, * , /, %
Comparison operators - ==, !=, >, >=, <, <=
Conditional operators - &&, ||
Ternary operator - ?:
Null coalescing operator- ??
Assignment operator
Assignment operator is used to assign a value to a variable, that is it assigns the
value on the right hand side to the variable on the left hand side
Example:
Int a = 10;
Arithmetic operators
Arithmetic operators are used to perform arithmetic operations
+ - Add
- - Subtract
* - Multiply
/ - Division
% - Modulus (divides the value on the left side by the value
on the right side and outputs the remainder )
Example:
9 % 2 = 1
Comparison operators
Comparison operators are used to compare the expression on the left hand side
(LHS) with the expression on the right hand side (RHS) and it outputs a boolean
value as the result
== - equal to
!= - not equal to
> - Greater than
>= - Greater than or equal to
< - Less than
<= - Less than or equal to
Conditional operators
Conditional operators are used to perform operations based on simultaneous
evaluation of multiple expressions
&& - and
Example:
If (a == b && b != c)
[if a equal to b and b not equal to c – this condition will
evaluate to true if and only if (a == b) is true and (b !=
c) is true]
|| - or
Example:
If (a == b || b != c)
[if a equal to b or b not equal to c – this condition will
evaluate to true if either of (a == b) is true or (b != c) is
true]
Ternary Operator (?:)
Ternary Operator is used to Return one value if the condition is true, or another
value if it is false. It is some sort of if-else code in a short form.
Example:
Null Coalescing operator (??)
A null coalescing operator returns the left-hand operand if the operand is not null;
otherwise it returns the right hand operand.
Example:
x ?? y , means if x is non-null, evaluate to x; otherwise, y.
In the syntax x ?? Y
x is the first operand which is a variable of a nullable type.
y is the second operand which has a non-nullable value of the same type.
While executing code, if x evaluates to null, y is returned as the value
The null coalescing operator (??) is right-associative which means it is evaluated
from right to left. So if you have an expression of the form x ?? y ?? z, this
expression is evaluated as x?? (y?? z)
Evaluation and operator precedence
In an expression that contains multiple operators, the order in which the operators
are applied is determined by operator precedence, associativity, and parentheses.
Each operator has a defined precedence. In an expression that contains multiple
operators that have different precedence levels, the precedence of the operators
determines the order in which the operators are evaluated.
For example, the following statement assigns 3 to n1.
n1 = 11 - 2 * 4;
The multiplication is executed first because multiplication takes precedence over
subtraction.
Associativity
When two or more operators that have the same precedence are present in an
expression, they are evaluated based on associativity.
Left-associative operators are evaluated in order from left to right. For example,
x * y / z is evaluated as (x * y) / z.
Right-associative operators are evaluated in order from right to left.
The assignment operator is right associative. For exmple:
The assignment operators and the ternary operator (?:) are right associative. All
other binary operators are left associative.
Adding paranthesis
We can change the order imposed by operator precedence and associativity by
using parentheses.
For example,
2 + 3 * 2 ordinarily evaluates to 8, because multiplicative operators take
precedence over additive operators.
However, if we write the expression as (2 + 3) * 2, the addition is evaluated before
the multiplication, and the result is 10
Operator overloading
We can change the behavior of operators for custom classes and structs. This
process is referred to as operator overloading
To overload an operator on a custom class requires creating a method on the class
with the correct signature. The method must be named "operator X" where X is
the name or symbol of the operator being overloaded.
Unary operators have one parameter, and binary operators have two parameters.
In each case, one parameter must be the same type as the class or struct that
declares the operator, as demonstrated in the following example:
public static Complex operator + (Complex c1, Complex c2)
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

Contenu connexe

Tendances (20)

CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
4.C#
4.C#4.C#
4.C#
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
C# Access modifiers
C# Access modifiersC# Access modifiers
C# Access modifiers
 
JDBC
JDBCJDBC
JDBC
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java threads
Java threadsJava threads
Java threads
 
Java swing
Java swingJava swing
Java swing
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 

Similaire à C# operators

This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxranaashutosh531pvt
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativityDr.Sandhiya Ravi
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativityDr.Sandhiya Ravi
 
Operators in Python
Operators in PythonOperators in Python
Operators in PythonAnusuya123
 
Conditional and special operators
Conditional and special operatorsConditional and special operators
Conditional and special operatorsMegha Sharma
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++Praveen M Jigajinni
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.netJaya Kumari
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperatorteach4uin
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cSowmya Jyothi
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++sanya6900
 

Similaire à C# operators (20)

c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
cprogrammingoperator.ppt
cprogrammingoperator.pptcprogrammingoperator.ppt
cprogrammingoperator.ppt
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
Conditional and special operators
Conditional and special operatorsConditional and special operators
Conditional and special operators
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Operators & Casts
Operators & CastsOperators & Casts
Operators & Casts
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
 
operator
operatoroperator
operator
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 

Plus de baabtra.com - No. 1 supplier of quality freshers

Plus de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Dernier

LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 

Dernier (20)

LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 

C# operators

  • 1.
  • 3. In C#, an operator is a program element that is applied to one or more operands in an expression or statement. Operators that take one operand, such as the increment operator (++) or new, are referred to as unary operators. Operators that take two operands, such as arithmetic operators (+,- ,*,/), are referred to as binary operators. One operator, the conditional operator (?:), takes three operands and is the sole ternary operator in C#.
  • 4. C# Operators - Classification Assignment operator - = Arithmetic operators - +, -, * , /, % Comparison operators - ==, !=, >, >=, <, <= Conditional operators - &&, || Ternary operator - ?: Null coalescing operator- ??
  • 5. Assignment operator Assignment operator is used to assign a value to a variable, that is it assigns the value on the right hand side to the variable on the left hand side Example: Int a = 10;
  • 6. Arithmetic operators Arithmetic operators are used to perform arithmetic operations + - Add - - Subtract * - Multiply / - Division % - Modulus (divides the value on the left side by the value on the right side and outputs the remainder ) Example: 9 % 2 = 1
  • 7. Comparison operators Comparison operators are used to compare the expression on the left hand side (LHS) with the expression on the right hand side (RHS) and it outputs a boolean value as the result == - equal to != - not equal to > - Greater than >= - Greater than or equal to < - Less than <= - Less than or equal to
  • 8. Conditional operators Conditional operators are used to perform operations based on simultaneous evaluation of multiple expressions && - and Example: If (a == b && b != c) [if a equal to b and b not equal to c – this condition will evaluate to true if and only if (a == b) is true and (b != c) is true] || - or Example: If (a == b || b != c) [if a equal to b or b not equal to c – this condition will evaluate to true if either of (a == b) is true or (b != c) is true]
  • 9. Ternary Operator (?:) Ternary Operator is used to Return one value if the condition is true, or another value if it is false. It is some sort of if-else code in a short form. Example:
  • 10. Null Coalescing operator (??) A null coalescing operator returns the left-hand operand if the operand is not null; otherwise it returns the right hand operand. Example: x ?? y , means if x is non-null, evaluate to x; otherwise, y. In the syntax x ?? Y x is the first operand which is a variable of a nullable type. y is the second operand which has a non-nullable value of the same type. While executing code, if x evaluates to null, y is returned as the value The null coalescing operator (??) is right-associative which means it is evaluated from right to left. So if you have an expression of the form x ?? y ?? z, this expression is evaluated as x?? (y?? z)
  • 11. Evaluation and operator precedence In an expression that contains multiple operators, the order in which the operators are applied is determined by operator precedence, associativity, and parentheses. Each operator has a defined precedence. In an expression that contains multiple operators that have different precedence levels, the precedence of the operators determines the order in which the operators are evaluated. For example, the following statement assigns 3 to n1. n1 = 11 - 2 * 4; The multiplication is executed first because multiplication takes precedence over subtraction.
  • 12. Associativity When two or more operators that have the same precedence are present in an expression, they are evaluated based on associativity. Left-associative operators are evaluated in order from left to right. For example, x * y / z is evaluated as (x * y) / z. Right-associative operators are evaluated in order from right to left. The assignment operator is right associative. For exmple: The assignment operators and the ternary operator (?:) are right associative. All other binary operators are left associative.
  • 13. Adding paranthesis We can change the order imposed by operator precedence and associativity by using parentheses. For example, 2 + 3 * 2 ordinarily evaluates to 8, because multiplicative operators take precedence over additive operators. However, if we write the expression as (2 + 3) * 2, the addition is evaluated before the multiplication, and the result is 10
  • 14. Operator overloading We can change the behavior of operators for custom classes and structs. This process is referred to as operator overloading To overload an operator on a custom class requires creating a method on the class with the correct signature. The method must be named "operator X" where X is the name or symbol of the operator being overloaded. Unary operators have one parameter, and binary operators have two parameters. In each case, one parameter must be the same type as the class or struct that declares the operator, as demonstrated in the following example: public static Complex operator + (Complex c1, Complex c2)
  • 15. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 16. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com