C#
  Home arrow C# arrow Behind the Scenes Look at C#: Operators
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Behind the Scenes Look at C#: Operators
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 31
    2005-06-29

    Table of Contents:
  • Behind the Scenes Look at C#: Operators
  • Arithmetic Operators
  • The Unary Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Assignment Operators
  • The Ternary Operator
  • Operator Precedence

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Behind the Scenes Look at C#: Operators


    (Page 1 of 8 )

    Have you ever wanted to gain an indepth knowledge of C# operators? This article, the first in a series, gets you off to a good start. It covers arithmetic operators (including unary arithmetic operators), relational operators, logical operators, assignment operators, the ternary operator, and operator precedence.

    The phrase "programming language operators" comes from the fact that operators are symbols and characters (as we will see later) that have been defined to perform an operation. I want make a note at this point before we go further that, to the runtime, there's no existence for operators, because the C# compiler generates method calls instead of using operators. For now, think of the expression x + y in C# as "int Add(x,y)" in the MSIL. That's why I will call x and y arguments to the operator, because those are in fact method arguments. Some of you would call them operands; that term is fine, too.

    When using operators, there must be a return value of the performed operation (which is much more like a return value of a method call). The operator arguments may be singular; in this case, we will call the operator a unary operator. You may be dealing with two arguments, in which case they would be called binary operators, and new to C# is the ternary operator, which takes three arguments (?:).

    Also note that operators are defined on the basis of type, so the .NET Framework permits us to write something like result = x + y; (where all these variables are primitive types), but you can't assume that Employee = Employee + Employee (where Employee is a user defined class). You need to overload the plus operator in order for this statement to work. Operator overloading will be discussed in detail in the second part of this article series.

    Most C# operators are overloaded to work with primitive data types such as byte, integer, single, double and decimal. For the string class, C# overloads the += assignment operator and the + operator, as we will see. Also, you can assign objects to references by using the = assignment operator (the System.Object overloads the = operator). As a consequence of overloading the assignment operator (=) on the object class, overloading the == and != operators is a must for the object class, too.

    We will discuss the various categories of C# operators, including arithmetic operators, relational operators, logical operators, and assignment, conditional and type Operators. We'll be throwing a lot of symbols around, so let's begin to discuss C# operators categories by the type of operations they perform on their arguments.

    More C# Articles
    More By Michael Youssef


     

    C# ARTICLES

    - Color Transformation in C# GDI+ Programming
    - Exceptions in C#
    - Overriding versus Overloading
    - Value Types and Reference Types
    - Defining Member and Type Visibility
    - Managing Files in C#
    - Working with Windows Registry in C#
    - Lossless Image Resizing in C#
    - Lossless Image Converting in C#
    - Creating an RSS Feed with ASP.Net Written in...
    - Polymorphism in C#
    - Inheritance in C#
    - C# Events Explained
    - C# Delegates Explained
    - C# StreamReader and StreamWriter Explained





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway