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 !






C#:Operators


Posted Date: 15 Aug 2008    Resource Type: Articles    Category: General

Posted By: Gaurav Arora       Member Level: Gold
Rating:     Points: 8



Scope: Scope of this article is upto its Title and motive to explain the C# Operators within minimum time and explaining with practical scenario.

The following table gives the brief overview of operators:for more details see Table:C#:Operators

Following table describes the C#:Operators:



Category

Operator

Arithmetic

+ - * / %

Logical

& | ^ ~ && || !

String concatenation

+

Increment and Decrement

++ --

Bit shifting

<< >>

Comparison

== != < > <= >=

Assignmnet

= += -= *= /= %= &= |= ^= <<= >>=

Member access

.

Indexing

[]

Cast

()

Conditional or Ternary operator

?:

Delegate Concatenation and removal

+ -

Creation of Object

new

Type information

sizeof is typeof as

Overflow excetion control

checked unchecked

Null coalescing operator [new in .net2.0]

??




The is and as operators
The is operator allows, whether an object is compatible with a specific type.

e.g. int i=10;
if ( i is object)
Console.WriteLine("i is an Object");


In above, message always display because all C# data types inherits from object.

The as operator is used to perform explicit type conversion of reference type. If the type being converted is compatible with the specific type, conversion is performed successfully. However, if the types are incompatible, the as operator returns the null value

Take a look on following code:

/* This Example is a part of different
* examples shown in Book:
* C#2005 Beginners: A Step Ahead
* Written by: Gaurav Arora
* Reach at : gaurav.aroraose@yahoo.co.in*/


// File name : isasoperator.cs

using System;

namespace CSharp.AStepAhead.isasoperator
{

class isasoperator
{
static void Main()
{

int i = 10;
if (i is object)
Console.WriteLine("i is am object and contains {0}", i);

object o1 = "This is object1";
object o2 = 5;
Console.WriteLine("Actual object values");
Console.WriteLine("o1 : {0} and o2 : {1}", o1, o2);

string str1 = o1 as string; //convert o1 to string
string str2 = o2 as string; //convert o2 to string

Console.WriteLine("After explicitly conversion using 'as' operator");
Console.WriteLine("str1 : {0} and str2 : {1}",str1,str2);

}
}
}





For more details, visit http://www.msdotnetheaven.com/ChaptersCsharp/csharplanguagei.htm




Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Interviews  .  C# Syntax  .  Article  .  .net  .  

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: C# Data Types
Previous Resource: Flow Control in C#
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use