- Back to Home »
- C#.NET »
- C#.NET Operators
Posted by :
Sudhir Chekuri
Wednesday, 30 December 2015
C# Operators are the symbols used in C# programming to performing different types of operations.
They are classified into arithmetic, assignment, unary, relational, logical, bitwise and shift operators.
Lets go in detail about the operators.
C# Arithmetic operators can be used to perform arithmetic operations between numeric variables values like int, long, float, double, decimal.
C# Arithmetic operators are as follows
+ (addition)
eg: a+b
- (subtraction)
eg: a-b
* (multiplication)
eg: a* b
/ (division)
eg: a/b
% (modulus)
eg: a%b
+ is used as an arithmetic operator if it is used to in between variables of numeric type.
+ is used as concatenation operator to combine two values if it is in between two text datatypes (or) text datatype and numeric datatype.
If you have to write a = a+ b; you can use += assignment operator to reduce that code to a+=b;
Like this we can use below C# Assignment operators to reduce the code as shown in the examples.
+=
Example: a+=b; ie., a=a+b;
-=
Example: a-=b; ie., a=a-b;
*=
Example: a*=b; ie., a=a*b;
/=
Example: a/=b; ie., a=a/b;
%=
Example: a%=b; ie., a=a%b;
They are classified into arithmetic, assignment, unary, relational, logical, bitwise and shift operators.
Lets go in detail about the operators.
C# Arithmetic Operators
C# Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication and division.C# Arithmetic operators can be used to perform arithmetic operations between numeric variables values like int, long, float, double, decimal.
C# Arithmetic operators are as follows
+ (addition)
eg: a+b
- (subtraction)
eg: a-b
* (multiplication)
eg: a* b
/ (division)
eg: a/b
% (modulus)
eg: a%b
+ is used as an arithmetic operator if it is used to in between variables of numeric type.
+ is used as concatenation operator to combine two values if it is in between two text datatypes (or) text datatype and numeric datatype.
C# Assignment operators
C# Assignment operators are used to reduce the code.If you have to write a = a+ b; you can use += assignment operator to reduce that code to a+=b;
Like this we can use below C# Assignment operators to reduce the code as shown in the examples.
+=
Example: a+=b; ie., a=a+b;
-=
Example: a-=b; ie., a=a-b;
*=
Example: a*=b; ie., a=a*b;
/=
Example: a/=b; ie., a=a/b;
%=
Example: a%=b; ie., a=a%b;
C# Increment decrement operators
C# Increment operator is used to increment numeric value by 1 and C# decrement operator is used to decrease numeric value by 1.
Increment and decrement operators looks like this
++ (C# Increment operator)
-- (C# decrement operator)
In increment we have pre increment and post increment.
In decrement we have pre decrement and post decrement.
Preincrement means increasing the value by 1 before the statement gets executed.
Example: ++i
If i is a variable of numeric type containing a value, it will get incremented by 1 before the statement gets executed.
Postincrement means increasing the value by 1 after the statement is executed.
Example: i++
If i is a variable of numeric type containing a value, it will get incremented by 1 after the statement gets executed.
i-- (post decrement)
i is decreased by 1 after the code is executed.
--i (pre decrement) i is decreased by 1 before the code gets executed.
C# Relational operators are as follows
> greater than
< less than
>= greater than or equal to
<= less than or equal to
== equals to
!= not equal to
&& (logical and) when both are true.
|| (logical or) when one of them is true.
~ (logical not) when both are false.
| (bitwise or)
^ (bitwise xor)
! (bitwise not)
C# Shift left operator works for multiplication. If we write 3<<4 that is equal to 3*2^4.
<< (shift left) (*)
eg: a=3<<4 ie., 3*2^4 =48
C# Shift right operator works for division. If we write 3>>4 that is equal to 3/2^4.
>> (shift right) (/) eg: a=3>>4 ie., 3/2^4 =146
Increment and decrement operators looks like this
++ (C# Increment operator)
-- (C# decrement operator)
In increment we have pre increment and post increment.
In decrement we have pre decrement and post decrement.
Preincrement means increasing the value by 1 before the statement gets executed.
Example: ++i
If i is a variable of numeric type containing a value, it will get incremented by 1 before the statement gets executed.
Postincrement means increasing the value by 1 after the statement is executed.
Example: i++
If i is a variable of numeric type containing a value, it will get incremented by 1 after the statement gets executed.
i-- (post decrement)
i is decreased by 1 after the code is executed.
--i (pre decrement) i is decreased by 1 before the code gets executed.
C# Relational operators
C# Relational operators are used to compare two values in variables. Used in if , for and while to check the conditions.C# Relational operators are as follows
> greater than
< less than
>= greater than or equal to
<= less than or equal to
== equals to
!= not equal to
C# Logical operators
C# Logical operators are logical and, logical or and logical not&& (logical and) when both are true.
|| (logical or) when one of them is true.
~ (logical not) when both are false.
C# Bit wise operators
& (bitwise and)| (bitwise or)
^ (bitwise xor)
! (bitwise not)
C# Shift operators
C# Shift operators are used to simply some mathematical operations like multiplication and division operators.C# Shift left operator works for multiplication. If we write 3<<4 that is equal to 3*2^4.
<< (shift left) (*)
eg: a=3<<4 ie., 3*2^4 =48
C# Shift right operator works for division. If we write 3>>4 that is equal to 3/2^4.
>> (shift right) (/) eg: a=3>>4 ie., 3/2^4 =146
Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.
ReplyDeletedigital marketing training in annanagar
digital marketing training in marathahalli
digital marketing training in rajajinagar
Digital Marketing online training
full stack developer training in pune
After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
ReplyDeletePython training in marathahalli
AWS Training in chennai
AWS Training in bangalore
Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
ReplyDeleteBlueprism online training
Blue Prism Training in Pune
Blueprism training in tambaram
Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
ReplyDeleteData Science training in kalyan nagar
Data Science training in OMR
selenium training in chennai
Data Science with Python training in chenni
Data Science training in chennai
Data science training in velachery
Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this.
ReplyDeletejava training in omr | oracle training in chennai
java training in annanagar | java training in chennai
Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
ReplyDeleteangularjs Training in bangalore
angularjs Training in btm
angularjs Training in electronic-city
angularjs online Training
angularjs Training in marathahalli
Does your blog have a contact page? I’m having problems locating it but, I’d like to shoot you an email. I’ve got some recommendations for your blog you might be interested in hearing
ReplyDeleteAmazon Web Services Training in Anna Nagar, Chennai |Best AWS Training in Anna Nagar, Chennai
Amazon Web Services Training in OMR , Chennai | Best AWS Training in OMR,Chennai
Amazon Web Services Training in Tambaram, Chennai|Best AWS Training in Tambaram, Chennai
AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR
I would like to thank the blog admin for sharing this useful information in my vision. I have been searching for this blog for a while.
ReplyDeleteBest TOEFL Coaching Institute in Ambattur
TOEFL Coaching Classes in Ambattur Estate
TOEFL Training in Thirumangalam
TOEFL velachery
TOEFL Training Institute near adambakkam
TOEFL Training in ekkaduthangal
TOEFL Classes near me
This information is impressive. I am inspired with your post writing style & how continuously you describe this topic. Eagerly waiting for your new blog keep doing more.
ReplyDeleteAWS Training in Chennai
aws training in bangalore
AWS Course in Chennai
aws course in bangalore
AWS Training centers in Chennai
ReplyDeleteYou write this post very carefully I think, which is easily understandable to me. Not only this, but another post is also good. As a newbie, this info is really helpful for me. Thanks to you.
Java training in Chennai
Java Online training in Chennai
Java Course in Chennai
Best JAVA Training Institutes in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Training
Java Online Training
Outstanding blog post, I have marked your site so ideally I’ll see much more on this subject in the foreseeable future.
ReplyDeletedata science training in chennai
data science training in tambaram
android training in chennai
android training in tambaram
devops training in chennai
devops training in tambaram
artificial intelligence training in chennai
artificial intelligence training in tambaram
Amazing stuff and I have marked your site so ideally I’ll see much more on this subject in the foreseeable future.
ReplyDeleteangular js training in chennai
angular js training in annanagar
full stack training in chennai
full stack training in annanagar
php training in chennai
php training in annanagar
photoshop training in chennai
photoshop training in annanagar
Title:
ReplyDeleteStudy Oracle Course in Chennai | Infycle Technologies
Description:
Did you want to set your career towards Oracle? Then Infycle is with you to make this into reality. Infycle Technologies gives the combined and best Oracle course in Chennai, which offers various stages of Oracle such as Oracle PL/SQL, Oracle DBA, etc., along with 100% hands-on training guided by experienced trainers in the field. Once after the training, the interviews will be arranged in the MNC's and firms for the placement. To have the Oracle with the best future, call 7502633633 and make this happen for your happy life.
Top Software training in Chennai
Infycle Technologies, the
ReplyDeletebest software training institute in Chennai offers the No.1 Python Certification in Chennai for tech professionals. Apart from the Python Course, other courses such as Oracle, Java, Hadoop, Selenium, Android, and iOS Development, Big Data will also be trained with 100% hands-on training. After the completion of training, the students will be sent for placement interviews in the core MNC's. Dial 7502633633 to get more info and a free demo.
Did you want to set your career towards Big Data? Then Infycle is with you to make this into reality. Infycle Technologies gives the combined and best Big Data Hadoop Training in Chennai, in 100% hands-on training guided by specialized trainers in the field. In addition to this, the mock interviews will be given to the candidates, so that they can face the interviews with complete confidence. Apart from all, the candidates will be placed in the top MNC's with a great salary package. To get it all, call 7502633633 and make this happen for your happy life.
ReplyDeleteBEST TRAINING IN CHENNAI
Finish the Selenium Training in Chennai from Infycle Technologies, No.1 software training institute in Chennai which is providing professional courses for students, freshers, experienced, and tech professionals. We provide courses like DevOps, Artificial Intelligence, Cyber Security, Python, Oracle, Java, Power BI, Digital Marketing, Data Science, etc. with the best trainers receiving amazing training for the best career. For more details and demo classes call 7504633633.
ReplyDelete