C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




OPERATORS IN C# 2.0


Posted Date: 23 Jun 2008    Resource Type: Articles    Category: .NET Framework
Author: anish vargheseMember Level: Silver    
Rating: Points: 12



OPERATORS IN C# 2.0



Different types of operators are:

1. Arithmetic
2. Bitwise
3. Relational and logical
4. Assignment Operator
5. ? Operator

1. Arithmetic



Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
-- Decrement

The operators +, -, *, and / all work the same way in C# as they do in any other computer language (or in algebra, for that matter). These can be applied to any built-in numeric data type.

2. Bitwise



Operator Result
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
>> Shift Right
<< Shift Left
~ One’s complement (unary NOT)
They perform Boolean logical operations.

3. Relational and logical



Relational operator produces true/false result .They often work with logical operator.

Operator Meaning
= = Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to


The logical operators, the operands must be of type bool, and the result of a logical operation is of type bool.

Operator Meaning
& AND
| OR
^ XOR (exclusive OR)
|| Short-circuit OR
&& Short-circuit AND
! NOT

Here most of them came with a doubt that. What is the difference between & and && or | and ||.


int d=1,n=10;

if (d != 0 && (n % d) == 0)
Console.WriteLine(d + " is a factor of " + n);

/* Now, try the same thing without short-circuit operator.
This will cause a divide-by-zero error. */
d = 0; n = 10;
if (d != 0 & (n % d) == 0)
Console.WriteLine(d + " is a factor of " + n);



Implies



Implies is the new logical operator in C#. It works as follows:

p q p implies q
True True True
True False False
False False True
False True True

4. Assignment Operator



The assignment operator is the single equal sign, =.

Example : x=y=10;

5. ? Operator



This is also known as ternary operator.

Syntax:


Exp1? Exp2:Exp3


If the Exp1 is true it returns the value of Exp2.Else it returns the value of Exp3.

Sample code:


int i=1,j;

j = i > 0 ? 2 : 3; // j = 2 because i>0 is true






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Operators  .  C# 2.0  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Insertion , Updation, Deletion of records to Sql Server with ADO.NET
Previous Resource: Working with Isolated Storage
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use