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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
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? 
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 / 29
    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

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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