ASP.NET Code
  Home arrow ASP.NET Code arrow Page 6 - ASP.NET Basics (part 2): Not My Type
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
ASP.NET CODE

ASP.NET Basics (part 2): Not My Type
By: Harish Kamath (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 33
    2003-07-30

    Table of Contents:
  • ASP.NET Basics (part 2): Not My Type
  • Building Blocks
  • A New Assignment
  • Strange Characters
  • Playing The Numbers
  • Operate With Caution
  • Everything Must Go
  • Cast And Credits
  • Mixing It Up
  • It's A Wrap

  • 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


    ASP.NET Basics (part 2): Not My Type - Operate With Caution


    (Page 6 of 10 )

    You'll remember how, in the first part of this tutorial, I used the + operator to add strings together. And just as you have the + operator for concatenating strings, C# comes with a bunch of other arithmetic operators designed to simplify the task of performing mathematical operations.

    The following example demonstrates the important arithmetic operators available in C#:


    <script language="C#" runat="server">
    void Page_Load()
    {
    // define some numeric variables
    int alphabeta

    // and some more
    int sumdifferenceproductquotient

    // initialize them
    alpha 69
    beta 96;

    sum alpha beta// addition
    difference beta alpha// subtraction
    product alpha beta// multiplication
    quotient beta alpha// integer division

    addition.Text "Sum of " alpha " and " beta " is " sum ".";
    subtraction.Text "Difference of " beta " and " alpha " is " difference ".";
    multiplication.Text "Product of " alpha " and " beta " is " product ".";
    division.Text "Quotient of " beta " by " alpha " is " quotient
    ".";

    }
    </script>
    <html>
    <head><title>Math Class</title></head>
    <body>
    <asp:label id="addition" runat="server" />

    <asp:label id="subtraction" runat="server" />

    <asp:label id="multiplication" runat="server" />
     <asp:label id="division" runat="server" />
     </body> </html> 

    And here is the output:

    As with all other programming languages, division and multiplication take precedence over addition and subtraction, although parentheses can be used to give a particular operation greater precedence. For example, the following statement


    <%
    result 10 4;
    %> 

    will store 18 in "result", while


    <%
    result = ((10 2) * 4);
    %>

    assigns 48 to the variable.

    In addition to these operators, C# comes with the very useful auto-increment (++) and auto-decrement (--) operators, which you'll see a lot of in forthcoming articles. The auto-increment operator increments the value of the variable by 1. The auto-decrement operator does the opposite. Here's an example which illustrates how this works


    <script language="C#" runat="server">
    void Page_Load()
    {
    // define a variable
    int x=99

    x++;
    // now x = 100

    x--;
    // now x = 99
    }
    </script>

    More ASP.NET Code Articles
    More By Harish Kamath (c) Melonfire


     

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek